首先,小程序:
#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++发布于 2011-08-18 22:11:50
看起来您需要编辑CodeLite项目设置并添加这些设置-lmysqlclient -lmysqlpp,您可以在命令行中传递这些设置。填充 and fields on tab。
发布于 2011-08-18 22:11:19
这些都是链接器错误。
在创建最终的可执行文件时,仍然必须提供对所有库函数的引用,就像编译单个翻译单元时所做的那样。
所以,这次也要将-lmysqlclient -lmysqlpp传递给g++。
如果使用的是集成开发环境,请相应地配置项目的生成设置。特别是,我看到了CodeLite has both "Compiler" and "Linker" build settings。你想要的是"Linker“设置。
有关构建过程(即编译、链接和差异)的更多信息,请阅读一本好的C++书籍。
https://stackoverflow.com/questions/7108740
复制相似问题