Resolving undefined references with MySQL C++ Connector

浪子不回头ぞ 提交于 2019-12-24 00:52:41

问题


I'm trying to compile this (also listed in the mysql c++ connector documentation): http://pastebin.com/HLv4zR0r

But I get these errors: http://pastebin.com/3t0UbeFy

This is how I tried compiling:

g++ -o test test.cpp `mysql_config --cflags --libs` -I./include/cppconn -L./lib -lmysqlcppconn-static

The result of running mysql_config --cflags --libs is:

-I/usr/include/mysql -DBIG_JOINS=1  -fno-strict-aliasing  -g
-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl

Edit:

After running Jonathan Wakely's suggested command with properly-ordered linker arguments,

g++ -o test test.cpp  -I./include/cppconn -L./lib -lmysqlcppconn-static `mysql_config --cflags --libs`

I get different errors: http://pastebin.com/4EWNgy9i


回答1:


The mysqlcppcon library depends on the mysqlclient C libraries, so you need to put the mysqlclient libs after -lmysqlcppconn-static

g++ -o test test.cpp  -I./include/cppconn -L./lib -lmysqlcppconn-static `mysql_config --cflags --libs`

The order of linker arguments matters. The linker looks at each file in order and decides if it needs any symbols from it. By the time it sees the libmysqlcppconn-static.a file it has already looked at (and ignored) the libmysqlclient.so library, and doesn't go back to look at it again.



来源:https://stackoverflow.com/questions/13348395/resolving-undefined-references-with-mysql-c-connector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!