C++ MySQL 链接器错误

标签 c++ mysql visual-studio-2010 linker-errors

我一直在尝试从数据库中获取一些值,所以我下载并安装了 this. 我包含了所需的 header 并遇到了此链接器错误。 (我也在使用 boost。)

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 " (__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<char,struct std::char_traits<char>,class std::allocator<char> > 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<char,struct std::char_traits<char> > & __cdecl std::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class sql::SQLString const &)" (??6std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@ABVSQLString@sql@@@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;
}

有谁知道那里可能发生了什么?

最佳答案

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

关于C++ MySQL 链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20537637/

相关文章:

c++ - 高效实现二分查找

c++ - 将具有多个空格的字符串添加到文本文件

mysql - 如何查找同 table 的 parent 和 child

visual-studio-2010 - 在 Visual Studio 中导出模板时如何添加相同解决方案项目引用?

c# - 如何使用 Moq 模拟 X509Certificate2?

c++ - cpp 中的嵌套对象创建。下面伪代码中的函数调用顺序是什么?

c++ - 如何删除指针的 STL 列表?

mysql - 如何从DB(MYSQL)获取信息并将值存储在JSP中的json中

mysql - 我的sql搜索语法实现

C# WatiN 下载文件 IE9