database.sarang.net
UserID
Passwd
Database
DBMS
ㆍMySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
MySQL Q&A 30001 게시물 읽기
No. 30001
MySQL C++ 연동 시에... LNK 에러때문에 골치썩고 있습니다.. 제발 도와주세요..ㅜㅜ
작성자
김정수(karl)
작성일
2011-06-05 18:29ⓒ
2011-06-05 18:31ⓜ
조회수
13,626

#include <iostream>
#include <tchar.h>
#include <windows.h>


#include <string>
#include <boost/lexical_cast.hpp>


#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>


using namespace std;


void print(string &msg)
{
 printf(msg.c_str());
 printf("\n");
}
int main()
{
 const string username = "root";
 const string password = "root";
 const string hostname = "tcp://localhost:3306";
 const string schema   = "test";


 sql::Driver *driver    = NULL;
 sql::Connection *con   = NULL;
 sql::Statement *stmt   = NULL;
 sql::PreparedStatement *pstmt = NULL;
 sql::ResultSet *res    = NULL;
 
 string output = "";
 try
 {


  driver = get_driver_instance();
  con    = driver->connect(hostname, username, password);
  con->setSchema(schema);


  con->setTransactionIsolation(sql::TRANSACTION_READ_COMMITTED);
  con->setAutoCommit(false);

 

  stmt = con->createStatement();
  { //한글 설정
   stmt->execute("set names euckr"); //for 한글
  }


  { //delete
   print(string("[delete] statement"));
   stmt->execute("delete from test");
   print(string(""));


  
   print(string("[insert] statement"));
   stmt->execute("insert into test values('hi', 'hi man~')");
   print(string(""));
  }

 

  { //statement select  
   print(string("[select] statement"));


   res = stmt->executeQuery("select * from test");
   output = "";
   int j = 1;
   while (res->next())
   {
    output.append(boost::lexical_cast<string>(j++)).append(".");
    output.append("\tt_str  : ").append(res->getString("t_str"));
   }
   print(output);
   delete res;
   res = NULL;
   print(string(""));
  }
 


  { //insert  
   print(string("[insert] preparestatement & binding"));


   pstmt = con->prepareStatement("insert into test (t_str, t_blob) values (?, ?)");
   pstmt->setString(1, "테스트1");


   string str = "테스트1의 blob 입니다.\n쨋든 방가..";
   pstmt->setBlob(2, new std::istringstream(str));


   pstmt->execute();
   delete pstmt;
   pstmt = NULL;
   print(string(""));
  }


 
  { //select
   print(string("[select] preparestatement & binding"));
   pstmt = con->prepareStatement("select t_str, t_blob from test where t_str like ?");
   pstmt->setString(1, "테스트%");
   res = pstmt->executeQuery();
   output = "";
   int i = 1;
   while (res->next())
   {
    output.append(boost::lexical_cast<string>(i++)).append(".");
    output.append("\tt_str  : ").append(res->getString("t_str")).append("\n");


    istream* is = res->getBlob("t_blob");
    string str = "";
    while (!is->eof())
    {
     char buff[512];
     is->getline(buff, 512);
     str += buff;
     str += "\n\t";
    }
    output.append("\tt_blob : ").append(str).append("\n");
   }
   print(output);
   print(string(""));
  }
 
  con->commit();
  //con->rollback();
 }
 catch (sql::SQLException &e)
 {
  string errmsg;
  errmsg.append("ErrorCode: [").append(boost::lexical_cast<string>(e.getErrorCode())).append("]\n");
  errmsg.append("SQLState : [").append(e.getSQLState()).append("]\n");
  errmsg.append("Cause    : [").append(e.what()).append("] ");
  print(errmsg);
 }


 if (stmt) delete stmt;
 if (res) delete res;
 if (pstmt) delete pstmt;
 if (con) delete con;


 return 0;
}

http://yamoe.tistory.com/159

여기에 있는 소스를 참조해서 했습니다.

거의 MySQL 레퍼런스 메뉴얼의 Complete Example이랑  비슷해서  따라하고 했는데 ....

MySQL 5.5 에는 lib 디렉토리 아래에 opt도 없고 뭔가 맞질 않아서

5.1의 라이브러리도 써보구

가능한 모든 설정이면 설정 다 해주고 했는데도


error LNK2019: "__declspec(dllimport) public: class std::basic_string,class std::allocator > const & __thiscall sql::SQLException::getSQLState(void)const " (__imp_?getSQLState@SQLException@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) 외부 기호(참조 위치: __catch$_main$0 함수)에서 확인하지 못했습니다.
 
error LNK2019: "__declspec(dllimport) public: int __thiscall sql::SQLException::getErrorCode(void)const " (__imp_?getErrorCode@SQLException@sql@@QBEHXZ) 외부 기호(참조 위치: __catch$_main$0 함수)에서 확인하지 못했습니다.

 error LNK2019: "__declspec(dllimport) public: __thiscall sql::SQLString::operator class std::basic_string,class std::allocator > const &(void)const " (__imp_??BSQLString@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) 외부 기호(참조 위치: _main 함수)에서 확인하지 못했습니다.
 
 error LNK2019: "__declspec(dllimport) public: __thiscall sql::SQLString::SQLString(char const * const)" (__imp_??0SQLString@sql@@QAE@QBD@Z) 외부 기호(참조 위치: _main 함수)에서 확인하지 못했습니다.

 error LNK2019: "__declspec(dllimport) public: __thiscall sql::SQLString::~SQLString(void)" (__imp_??1SQLString@sql@@QAE@XZ) 외부 기호(참조 위치: _main 함수)에서 확인하지 못했습니다.
 
error LNK2019: "__declspec(dllimport) public: __thiscall sql::SQLString::SQLString(class std::basic_string,class std::allocator > const &)" (__imp_??0SQLString@sql@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 외부 기호(참조 위치: _main 함수)에서 확인하지 못했습니다.

 error LNK2019: __imp__get_driver_instance 외부 기호(참조 위치: _main 함수)에서 확인하지 못했습니다. D:\C++ Project\YongInProject\Debug\YongInProject.exe : fatal error LNK1120: 7개의 확인할 수 없는 외부 참조입니다.
 

이거와  lnk2001 에러가 나네요....

dll 파일 실행 디렉토리와 system32에 놓으란 말도 있어서 거기다가도 놓았구여

라이브러리도 전처리기에 바로 해주기도 하고 프로젝트 속성에서 링크-> 입력에다가도 놓고

다 해봤는데도 뭐가 문제인지 잘 모르겠네요..

저번엔 오라클도 연동해보려고 하다가 또 저런 에러나서 MySQL로 변경해서 해보려고 하는데 또 오류나고......

참고로 저는 64비트 VS 2008 사용하고 있습니다.

MySQL은 5.5 버전이구여 MySQL connector C++ 1.1.0 , boost 깔려있습니다.

 

이 글에 대한 댓글이 총 1건 있습니다.

해당 링크 에러는 DLL 등과는 관계가 없습니다.

헤더는 올바르게 참조되어, 컴파일에는 문제가 없었는데 실행 파일로 만드는 링크 과정에서 적절한 라이브러리를 찾지 못한 상태입니다. preprocessor 항목에 'CPPCONN_PUBLIC_FUNC=' 를 추가하셨는지 확인하시는 것이 좋겠습니다.

 

다음의 링크를 참조하세요 : http://blog.ulf-wendel.de/?p=215

 

박현우(lqez)님이 2011-06-06 23:13에 작성한 댓글입니다.
[Top]
No.
제목
작성자
작성일
조회
30004mysql에서 오라클디비 가져오기 [1]
최봉수
2011-06-08
8733
30003innodb 데이터 이전 작업시. [2]
신희창
2011-06-07
9016
30002로우계산과 컬럼합치는 문제에 대해 문의드립니다 [2]
박세정
2011-06-07
8029
30001MySQL C++ 연동 시에... LNK 에러때문에 골치썩고 있습니다.. 제발 도와주세요..ㅜㅜ [1]
김정수
2011-06-05
13626
30000mysql_connect 에러.. [1]
초보
2011-06-03
8735
29999mysql innodb_data_home_dir 변경 후 권한에러로 실행이 안됩니다. [1]
김영범
2011-06-03
8516
29998MySQL을 이용해 아주 간단한 게시판을 만들어 보려는데요. [1]
Srin
2011-05-30
8489
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2023 DSN, All rights reserved.
작업시간: 0.049초, 이곳 서비스는
	PostgreSQL v16.1로 자료를 관리합니다