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

时间:2017-09-20 13:21:20

标签: mysql windows-ce linker-errors dllimport lnk2019

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

  

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连接。 初步想法:我是否需要将.dll / .lib文件导入我的WinCe设备?

这是我的代码:

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;
}

0 个答案:

没有答案