c 连接mysql错误信息,C ++ MySQL链接器错误

I have been trying to fetch some values from a database, so I downloaded & installed this.

I included the needed headers and faced this linker errors. (I'm also using boost.)

error LNK2019: unresolved external symbol "__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) referenced in function __catch$_main$0

error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall sql::SQLException::getErrorCode(void)const " (__imp_?getErrorCode@SQLException@sql@@QBEHXZ) referenced in function __catch$_main$0

error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::~SQLString(void)" (__imp_??1SQLString@sql@@QAE@XZ) referenced in function _main

error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::SQLString(char const * const)" (__imp_??0SQLString@sql@@QAE@QBD@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,class std::allocator > const & __thiscall sql::SQLString::asStdString(void)const " (__imp_?asStdString@SQLString@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "class std::basic_ostream > & __cdecl std::operator< > &,class sql::SQLString const &)" (??6std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@ABVSQLString@sql@@@Z)

fatal error LNK1120: 6 unresolved externals

I also got a couple of warnings like this:

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

#include "stdafx.h"

#include

#include

#include "mysql_connection.h"

#include

#include

#include

#include

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;

}

Does anyone know what may happened there ?

解决方案

Have you also add correct library ? It seems (you write, you have added headers), that you are running Visual Studio, so either do #pragma comment(lib, ) or add that lib in projects settings under Linker

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值