为什么`sqlpp-mysql`不能正确链接?

时间:2016-10-14 07:19:19

标签: c++ mysql database c++11 linker

我正在尝试使用sqlpp-connector-mysql建立数据库连接。在我尝试运行SampleTest.cpp时构建此项目后,会产生错误

$ g++ -std=c++1y -lsqlpp-mysql SampleTest.cpp

SampleTest.cpp:(.text+0x12f): undefined reference to `sqlpp::mysql::connection::connection(std::shared_ptr<sqlpp::mysql::connection_config> const&)'
SampleTest.cpp:(.text+0x13e): undefined reference to `sqlpp::mysql::connection::~connection()'
SampleTest.cpp:(.text+0x157): undefined reference to `sqlpp::mysql::connection::connection(std::shared_ptr<sqlpp::mysql::connection_config> const&)'
SampleTest.cpp:(.text+0x19d): undefined reference to `sqlpp::mysql::connection::execute(std::string const&)'
SampleTest.cpp:(.text+0x201): undefined reference to `sqlpp::mysql::connection::execute(std::string const&)'
SampleTest.cpp:(.text+0x265): undefined reference to `sqlpp::mysql::connection::execute(std::string const&)'
SampleTest.cpp:(.text+0x2c9): undefined reference to `sqlpp::mysql::connection::execute(std::string const&)'

我认为,sqlpp-mysql没有正确链接。有人可以给我一些指针,如何解决这个问题?

P.S:我已经建立了要求。

我像这样构建了sqlpp11sqlpp11-connector-mysql

$ cd project_dir
$ cmake CmakeList.txt
$ sudo make install

1 个答案:

答案 0 :(得分:0)

我需要正确链接库。

g++ -std=c++11 tests/SampleTest.cpp -I ../../sqlpp11/include -I . -I ../../date -lsqlpp-mysql -lmysqlclient