0

As I try to compile my code, I get this error:

1>Main.obj : error LNK2019: unresolved external symbol "__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) referenced in function __catch$57778

Now there are a couple more, but I think solving this one, will solve the others as well.

I'm trying to get a SQL connection from an WinCe 6.0 Device to a Server. First thoughts: Do I need to import the .dll/.lib files to my WinCe device?

Here's my code:

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;
}
valiano
  • 16,433
  • 7
  • 64
  • 79
Treak
  • 1
  • 1
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Baum mit Augen Sep 20 '17 at 16:05
  • You need the (_MySQL_) _.lib_ file at build (_link_) time, and the corresponding _.dll_ file (if any - or in other words if _MySQL_ is built as a _Dynamic Link Library_) at runtime. – CristiFati Oct 14 '17 at 21:36

0 Answers0