VS错误LNK2019,MySQL代码调用__declspec(dllimport)错误

VS error LNK2019, MySQL code invokes __declspec(dllimport) error

提问人:Treak 提问时间:9/20/2017 最后编辑:valianoTreak 更新时间:10/9/2017 访问量:36

问:

当我尝试编译我的代码时,我收到以下错误:

1>Main.obj:错误LNK2019:无法解析的外部符号“__declspec(dllimport) public: class std::basic_string,class std::allocator > const & __cdecl sql::SQLException::getSQLState(void)const ” (__imp_?getSQLState@SQLException@sql@@QBAABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) 在函数中引用__catch$57778

现在还有几个,但我认为解决这个,也会解决其他的。

我正在尝试获取从 WinCe 6.0 设备到服务器的 SQL 连接。 第一个想法:我需要将 / 文件导入我的 WinCe 设备吗?.dll.lib

这是我的代码:

include <windows.h>
include <ScanCApi.h>
include <iostream>
include <cppconn/driver.h>
include <cppconn/exception.h>
include <cppconn/resultset.h>
include <cppconn/statement.h>
include <stdlib.h>

int wmain() {
    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("test");

        stmt = con->createStatement();
        res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
        while (res->next()) {
            std::cout << "\t... MySQL replies: ";
            /* Access column data by alias or column name */
            std::cout << res->getString("_message") << std::endl;
            std::cout << "\t... MySQL says it again: ";
            /* Access column data by numeric offset, 1 is the first column */
            std::cout << res->getString(1) << std::endl;
        }
        delete res;
        delete stmt;
        delete con;
    } catch (sql::SQLException &e) {
        std::cout << "# ERR: SQLException in " << __FILE__;
        std::cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << 
        std::endl;
        std::cout << "# ERR: " << e.what();
        std::cout << " (MySQL error code: " << e.getErrorCode();
        std::cout << ", SQLState: " << e.getSQLState() << " )" << std::endl;
    }
    return 0;
}
mysql windows-ce 链接器错误 dllimport lnk2019

评论

0赞 Baum mit Augen 9/21/2017
什么是未定义的引用/未解析的外部符号错误以及如何修复它?
0赞 CristiFati 10/15/2017
在构建(链接)时需要 (MySQL) .lib 文件,在运行时需要相应的 .dll 文件(如果有的话 - 换句话说,如果 MySQL 是作为动态链接库构建的)。

答: 暂无答案