2013-12-12 95 views
2

我一直在试图从数据库中获取一些值,所以我下载了&安装了this. 我包含了所需的头文件并面对这个链接器错误。 (我还使用升压)C++ MySQL链接器错误

error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __thiscall sql::SQLException::getSQLState(void)const " ([email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@XZ) referenced in function __catch$_main$0 
error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall sql::SQLException::getErrorCode(void)const " ([email protected]@[email protected]@QBEHXZ) referenced in function __catch$_main$0 
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::~SQLString(void)" ([email protected]@@[email protected]) referenced in function _main 
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::SQLString(char const * const)" ([email protected]@@[email protected]@Z) referenced in function _main 
error LNK2019: unresolved external symbol __imp__get_driver_instance referenced in function _main 
error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __thiscall sql::SQLString::asStdString(void)const " ([email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@XZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class sql::SQLString const &)" ([email protected]@[email protected][email protected]@[email protected]@@[email protected]@[email protected]@@@Z) 
fatal error LNK1120: 6 unresolved externals 

我也有这样的一些警告:

warning C4251: 'sql::mysql::MySQL_Connection::proxy' : class 'boost::shared_ptr<T>' needs to have dll-interface to be used by clients of class 'sql::mysql::MySQL_Connection'

#include "stdafx.h" 
#include <stdlib.h> 
#include <iostream> 
#include "mysql_connection.h" 

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

using namespace std; 

int main(void) 
{ 
    try 
    { 
     sql::Driver *driver; 
     sql::Connection *con; 
     sql::Statement *stmt; 
     sql::ResultSet *res; 

     /* Create a connection */ 
     driver = get_driver_instance(); 
     con = driver->connect("tcp://127.0.0.1:3306", "root", "root"); 
     /* Connect to the MySQL test database */ 
     con->setSchema("trinity"); 

     stmt = con->createStatement(); 
     res = stmt->executeQuery("SELECT * FROM test WHERE test='Tester'"); // replace with your statement 
     while (res->next()) 
     { 
      cout << "\t... MySQL replies: "; 
      /* Access column data by alias or column name */ 
      cout << res->getString("_message") << endl; 
      cout << "\t... MySQL says it again: "; 
      /* Access column fata by numeric offset, 1 is the first column */ 
      cout << res->getString(1) << endl; 
     } 
     delete res; 
     delete stmt; 
     delete con; 

    } 
    catch (sql::SQLException &e) 
    { 
     cout << "# ERR: SQLException in " << __FILE__; 
     cout << "(\" << __FUNCTION__ << \") on line " << "»" << __LINE__ << endl; 
     cout << "# ERR: " << e.what(); 
     cout << " (MySQL error code: " << e.getErrorCode(); 
     cout << ", SQLState: " << e.getSQLState() << ")" << endl; 
    } 

    cout << endl; 

    return EXIT_SUCCESS; 
} 

有谁知道什么可能发生呢?

回答

2

你还添加了正确的库吗?它似乎(你写,你已经添加了标题),你正在运行Visual Studio,所以要么#pragma comment(lib, <mysql lib>)或添加该链接器下的项目设置中的该库

+1

已经这样做,它不起作用。 – Blacktempel

+0

因此...我删除了所有库并重新安装了MySQL连接器。现在我正面临着这个令人敬畏的错误。仅供参考,这个'.dll'文件和库一样在SAME文件夹中。该程序无法启动,因为您的计算机缺少mysqlcppconn.dll。请尝试重新安装程序来解决此问题.' – Blacktempel

+1

DLL应位于文件夹中,从您运行程序的位置或某个系统dll目录中。如果你正在通过VS运行程序,比库(我认为),在项目目录(其中vcproj和其他文件),而不是在调试/版本 –