G ++ mysql linker error

I am trying to compile a program written in C ++ with the following command line:

g++ test.cpp pugixml-1.0/src/pugixml.cpp -lcurl -lmysqlclient -lmysqlcppconn-static -lboost_thread

This works well on a 32-bit Debian machine, but does not work on Ubuntu 64 Bit, and I don't know why. I installed all the necessary packages for using mysql. The error message is as follows:

/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libmysqlcppconn-static.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::thread_init()':
(.text+0x1): undefined reference to `mysql_thread_init'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libmysqlcppconn-static.a(mysql_client_api.cpp.o): In function `sql::mysql::NativeAPI::LibmysqlStaticProxy::thread_end()':
(.text+0x11): undefined reference to `mysql_thread_end'
etc. ...
collect2: ld returned 1 exit status

The message is quite long, and all lines look very similar to changing links;)

+3
source share
1 answer

Try to invert the order -lmysqlclient -lmysqlcppconn-staticin your linker call.

If object A needs characters from object B, A must be in front of B on the linker command line.

+3
source

All Articles