0

首先,小程序:

#include <mysql++.h>
using namespace mysqlpp;

void mainuu ()
{ Connection conn("mysql", "localhost", "root", "pwd");}

如果我将它编译为 CodeLite 中的一个文件或以这种方式:

g++ -I/usr/include/mysql -I/usr/include/mysql++ -lmysqlclient -lmysqlpp -o Test mysql_api.cpp

没关系,但是当我尝试用这个文件构建整个项目时,我得到了这个:

g++ -o ./Debug/server ./Debug/main.o ./Debug/log.o ./Debug/packet.o ./Debug/mysql_api.o  -L.   
./Debug/mysql_api.o: In function `mainuu()':
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:10: undefined reference to `mysqlpp::Connection::Connection(char const*, char const*, char const*, char const*, unsigned int)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:12: undefined reference to `mysqlpp::Connection::query(char const*)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:13: undefined reference to `mysqlpp::SQLTypeAdapter::SQLTypeAdapter(char const*, bool)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:13: undefined reference to `mysqlpp::operator<<(mysqlpp::quote_type1, mysqlpp::SQLTypeAdapter const&)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:19: undefined reference to `mysqlpp::operator<<(std::basic_ostream<char, std::char_traits<char> >&, mysqlpp::String const&)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:10: undefined reference to `mysqlpp::Connection::~Connection()'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:10: undefined reference to `mysqlpp::Connection::~Connection()'
./Debug/mysql_api.o: In function `mysqlpp::Row::operator[](int) const':
/usr/include/mysql++/row.h:328: undefined reference to `mysqlpp::Row::at(unsigned int) const'
./Debug/mysql_api.o: In function `mysqlpp::Query::store()':
/usr/include/mysql++/query.h:467: undefined reference to `mysqlpp::Query::str(mysqlpp::SQLQueryParms&)'
/usr/include/mysql++/query.h:467: undefined reference to `mysqlpp::SQLTypeAdapter::SQLTypeAdapter(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
/usr/include/mysql++/query.h:467: undefined reference to `mysqlpp::Query::store(mysqlpp::SQLTypeAdapter const&)'
collect2: ld returned 1 exit status
make[1]: *** [Debug/server] Error 1
make[1]: Leaving directory `/home/asyler/.codelite/workspace/test/server'
make: *** [All] Error 2

这是 CodeLite g++ 编译器设置:

-g -I/usr/include/mysql -I/usr/include/mysql++ -lmysqlclient -lmysqlpp -L/usr/lib/mysql -L/usr/lib/mysql++ -lmysql++
4

2 回答 2

1

这些是链接器错误。

当您创建最终的可执行文件时,您仍然必须提供对所有库函数的引用,就像您在编译单个翻译单元时所做的那样。

所以,也-lmysqlclient -lmysqlppg++这个时候。

如果您使用的是集成开发环境,请相应地配置项目的构建设置。特别是,我看到CodeLite 同时具有“编译器”和“链接器”构建设置。您需要的是“链接器”设置。

有关构建过程的更多信息(即编译、链接和区别),请阅读一本好的 C++ 书籍。

于 2011-08-18T14:11:18.867 回答
1

看起来您需要编辑 CodeLite 项目设置并添加-lmysqlclient -lmysqlpp您在命令行中传递的这些设置。填写链接器选项卡上的库路径字段

于 2011-08-18T14:11:49.757 回答