undefined reference to 'get_driver_instance'

12,506

Solution 1

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)

Solution 2

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

Share:
12,506
Azeem Michael
Author by

Azeem Michael

My name is Azeem Michael. I have a BS degree in computer science and have been working as a software engineering in NYC for the past 9 years. I enjoy MVC frameworks like symfony and Laravel and have extensive knowledge working with both SQL and NoSQL solutions like MongoDB and Neo4J graph database. You may read more about me at Azeem Michael on about.me (http://about.me/azeemmichael) or Azeem Michael (http://azeemmichael.blogspot.com) — Azeem Michael

Updated on June 06, 2022

Comments

  • Azeem Michael
    Azeem Michael almost 2 years

    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?