2014-08-30 2 views
1

모두. 나는 mysql을 연결하는 C++를 사용하려면,하지만 작동하지 않습니다 오류 정보는 다음과 같습니다mysql C++ 커넥터 연결 오류

error LNK2019: unresolved external symbol "__declspec(dllimport) public: char const * __thiscall sql::SQLString::c_str(void)const " ([email protected]@[email protected]@QBEPBDXZ) referenced in function [email protected]@YAXXZ$0 
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::~SQLString(void)" ([email protected]@@[email protected]) referenced in function "void __cdecl RunConnectMySQL(void)" ([email protected]@YAXXZ) 
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::SQLString(char const * const)" ([email protected]@@[email protected]@Z) referenced in function "void __cdecl RunConnectMySQL(void)" ([email protected]@YAXXZ) 
error LNK2019: unresolved external symbol "__declspec(dllimport) class sql::mysql::MySQL_Driver * __cdecl sql::mysql::get_driver_instance(void)" ([email protected]@[email protected]@[email protected]@XZ) referenced in function "class sql::mysql::MySQL_Driver * __cdecl sql::mysql::get_mysql_driver_instance(void)" ([email protected]@[email protected]@[email protected]@XZ) 

그리고 I에 유래에서 같은 질문을 검색해야하지만, 적절한 대답을하지 않았다. 내 코드 :

#include <iostream> 
#include <string> 
#include <mysql_connection.h> 
#include <mysql_driver.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 RunConnectMySQL() 
{ 
    sql::mysql::MySQL_Driver *driver = NULL; 
    sql::Connection *con = NULL; 
    Statement *state = NULL; 
    ResultSet *result = NULL; 
    try 
    { 
     driver = sql::mysql::get_mysql_driver_instance(); 
     con = driver->connect("tcp://127.0.0.1:3306","root",""); 
     state = con->createStatement(); 
     state->execute("use monitor"); 
     result = state->executeQuery("select * from address"); 
    } 
    catch(sql::SQLException & ex) 
    { 
     cout<<ex.what()<<endl; 
     return; 
    } 

    while(result->next()) 
    { 
     cout<<"source: "<<result->getString("source").c_str()<<endl; 
    } 
    state->close(); 
} 

int main() 
{ 
    RunConnectMySQL(); 
    system("pause"); 
    return 0; 
} 

감사합니다.

답변

2

실행 파일에 MySQL 커넥터 라이브러리를 연결해야합니다. 이 작업을하기 전에 어떤 종류의 연결을 선택해야하는지 결정해야합니다. MySQL 커넥터는 정적 또는 동적의 두 가지 종류의 링크를 지원합니다.

official website에는 두 유형의 링크를 사용하여 Netbeans에서 간단한 프로젝트를 만드는 방법을 보여주는 자습서가 있습니다. Netbeans를 사용하는지는 모르지만 다른 IDE에서 설명한 작업을 복제 할 수 있다고 확신합니다.

마지막으로 MySQL 커넥터를 올바르게 설치했는지 확인하십시오. 운영 체제에서이 작업을 수행하는 방법을 이해하려면 official documentation을 살펴보십시오.