3

I'm getting "undefined reference to 'get_driver_instance'" when building even the most simple example from: http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-examples-complete-example-1.html. It builds and runs fine on my local machine but it won’t build on the server – seems like linking mysql library issue.
This is my build cmd:
g++ -o test -Iinclude -Llib -L/usr/lib64/mysql main.cpp

I can’t run the local built binary on the server as it was built using dynamic 'libmysqlclient.so'. I also tried to install the static libmysqlclient.a on my local machine but I can’t find ‘libmysqlclient.a’ in my /usr/lib/mysql dir. I assume Only way to run it on the server is if I can either build it statically on my local machine or I can compile and build it directly on the server. I tried ‘sudo yum install mysql-devel’ but I only see libmysqlclient.so -- can’t find ‘libmysqlclient.a’. Is there a way to install a static mysqlclient on my local linux or is my build cmd wrong? How can I build source code on the server?

Azeem Michael
  • 193
  • 1
  • 4
  • 15

2 Answers2

14

try adding -lmysqlcppconn to your linker options. I answered just for this to have an answer (even though this was asked 2 years ago :D)

Gerald Torres
  • 403
  • 6
  • 18
  • @Gerald: `g++ -o test -Iinclude -Llib -L/usr/mysql -lmysqlcppconn temp.cpp ` or `g++ -o test -Iinclude -Llib -L/usr/mysql temp.cpp -lmysqlcppconn` which one is correct? both gives error.First one gives same as this question and 2nd gives some bunch of errors for libmysqlcppconn.so – Catty Sep 06 '13 at 14:33
1

try to add '-lmysqlclient' to the command, i.e.: g++ -o test -Iinclude -Llib -L/usr/lib64/mysql -lmysqlclient main.cpp

shuvalov
  • 4,713
  • 2
  • 20
  • 17
  • hi shuvalov, tried but no success. seems like i'm having a linking issue with mysql-connector/c++ header files. This is how my folder structured: /include --> contains /cppconn and mysql_driver.h and mysql_connection.h. /lib --> contains downloaded /lib dir of mysqlc++-connector. /usr/lib64/mysql --> contains libmysqlclient – Azeem Michael Aug 10 '10 at 15:38