cannot find -lmysqlclient

K_U picture K_U · Nov 16, 2010 · Viewed 20.4k times · Source

I'm trying to compile a C++ program and one of the classes uses . g++ is not able to find the libraries would be my guess. The command i use to compile is -

g++ c1.cpp c2.cpp c3.cpp c4.cpp -o c4 -lm -lmysqlclient

c3.cpp is the file that needs mysql.h. This works perfectly on my local machine, but refuses to run on the server with the error

cannot find -lmysqlclient

I tried finding the libmysqlclient.so files on the server using the find command, I don't think they are present there

uname -a

reveals

SunOS opteron 5.10 Generic_139556-08 i86pc i386 i86pc
user@opteron 12:26:02 ~/c++/projname/

I realize that i need to link some libraries, but where and how?

Any help would be appreciated. Thanks.

Answer

Sri Hari Y.S picture Sri Hari Y.S · Apr 4, 2016

Whatever library packages u think is not installed can be installed using sudo apt-get install. But the problem is to find the right name of the package apt-get can understand. So how to do that ?! simple

use command : sudo apt-cache search <filename>

For eg.: in this case lmysqlclient

sudo apt-cache search mysqlclient

(remember to exclude 'l' from the actual name ,ie, mysqlclient and not lmysqlclient). This outputs:

libmysqlclient-dev - MySQL database development files

In the above -libmysqlclient-dev is the name that apt-get can recognize and solve our cannot find lmysqlclient problem

so now type: sudo apt-get install libmysqlclient-dev from interface. After its done, try making your required file.