简体   繁体   中英

MySQL C++ Connector linking errors

I am trying to set up a connection to a MySQL database. The code compiles fine, but when linking I always get errors. I've tried both dynamic and static linking but nothing works. Some of the errors:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall mysqlx::abi2::r0::Error::Error(char const *)" (__imp_??0Error@r0@abi2@mysqlx@@QAE@PBD@Z) referenced in function "protected: void __thiscall mysqlx::abi2::r0::Value::check_type(enum mysqlx::abi2::r0::Value::Type)const " (?check_type@Value@r0@abi2@mysqlx@@IBEXW4Type@1234@@Z)  DatabaseTest    

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall mysqlx::abi2::r0::DbDoc::~DbDoc(void)" (__imp_??1DbDoc@r0@abi2@mysqlx@@QAE@XZ) referenced in function "public: __thiscall mysqlx::abi2::r0::Value::~Value(void)" (??1Value@r0@abi2@mysqlx@@QAE@XZ) DatabaseTest    

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall mysqlx::abi2::r0::DbDoc::DbDoc(void)" (__imp_??0DbDoc@r0@abi2@mysqlx@@QAE@XZ) referenced in function "public: __thiscall mysqlx::abi2::r0::Value::Value(void)" (??0Value@r0@abi2@mysqlx@@QAE@XZ)   DatabaseTest     


#include <iostream>
#include "mysqlx/xdevapi.h"

int main()
{
    //short test, program doesn't compile, the headers aren't included here because they are more than 1000 lines long. You can get them at the MySQL homepage
    return 0;
}

I use the newest version of the connector. You can download the project here if you want to check the settings. Does anybody have an idea?

First, find where is your mysqlx directory is located, using following command:

sudo find / -name mysqlx

In Debian system, it is usually located in /usr/include/mysql-cppconn-8/ . For compiling, use folllowing command:

g++ -std=c++11 -I /usr/include/mysql-cppconn-8/ -lmysqlcppconn8 filename.cpp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM