mysqlpp中的引用错误

时间:2013-12-06 18:12:12

标签: c++ ld mysqlpp


和其他许多人一样,我有问题要编译一个程序,包括mysqlpp mysqlpp似乎安装正确,库路径也在/etc/ld.so.conf中正确设置并且是已知的(所以我认为):

$ sudo ldconfig -p | grep mysql
libmysqlpp.so.3 (libc6,x86-64) => /usr/local/lib/libmysqlpp.so.3
libmysqlpp.so (libc6,x86-64) => /usr/local/lib/libmysqlpp.so
libmysqlclient.so.18 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18
libmysqlclient.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libmysqlclient.so

但似乎有些错误,编译器找不到mysqlpp库。
链接编译器命令:

 /usr/bin/c++ -lm -L/usr/lib -L/usr/lib/x86_64-linux-gnu/ -lmysqlclient -lmysqlpp -o myprogram  myprogram.o

错误消息缺少mysqlpp引用(除了许多其他缺少的引用之外):

/usr/local/include/mysql++/row.h:328: undefined reference to `mysqlpp::Row::at(unsigned long) const'
myprogram.o: In function `mysqlpp::StoreQueryResult::operator=(mysqlpp::StoreQueryResult const&)':
/usr/local/include/mysql++/result.h:252: undefined reference to `mysqlpp::StoreQueryResult::copy(mysqlpp::StoreQueryResult const&)'
myprogram.o: In function `long mysqlpp::String::do_conv<long>(char const*) const':
/usr/local/include/mysql++/mystring.h:615: undefined reference to `mysqlpp::String::length() const'
/usr/local/include/mysql++/mystring.h:615: undefined reference to `mysqlpp::String::data() const'
collect2: ld returned 1 exit status

我在我的智慧结束。也许你们中的某些人可以帮助我。谢谢!

1 个答案:

答案 0 :(得分:1)

链接器以相反的顺序查找依赖项,因此您需要在命令行上的对象(或源)文件之后放置库

$ c++ myprogram.o -o myprogram -lm -L/usr/lib -L/usr/lib/x86_64-linux-gnu/ -lmysqlclient -lmysqlpp