Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot find -lmysqlclient

Tags:

mysql

solaris

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.

like image 449
K_U Avatar asked Nov 16 '10 20:11

K_U


People also ask

How do you fix Ld Cannot find?

Compile Time To resolve this problem, you should either provide the library file ( lib{nameOfTheLibrary}. so ) in those search paths or use -L command option. -L{path} tells the g++ (actually ld ) to find library files in path {path} in addition to default paths.

What usr bin Ld Cannot find?

A message such as /usr/bin/ld: cannot find -linput actually means it was looking for a file named libinput.so . The -l flag is a command-line argument (to ld or to gcc ) that expects the library name to follow and then the library name is used to form the file name which includes the lib prefix and the .


4 Answers

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.

like image 195
Sri Hari Y.S Avatar answered Oct 03 '22 15:10

Sri Hari Y.S


Simplifying @SriHariY.S's answer-

Try installing it with sudo apt-get install libmysqlclient-dev.

like image 35
Swaps Avatar answered Oct 03 '22 15:10

Swaps


Do you have the MySQL client libraries? Can you look for it as

find / -name "libmysqlclient.so" -type f -print 2>/dev/null

Also, you can use the -R flag on linker to hardlink the libmysqlclient as

g++ -R/usr/local/mysql/lib ....

Or, you can export the LD_LIBRARY_PATH_32 or LD_LIBRARY_PATH_64 as

export LD_LIBRARY_PATH_32=$MYSQL_HOME/lib

Urko,

like image 27
itilys Avatar answered Oct 03 '22 13:10

itilys


On Ubuntu 18 I used this command to find a name of required package for fixing this error:

apt search lmysqlclient

After this I installed missing package:

sudo apt install libmariadbclient-dev-compat
like image 32
yesnik Avatar answered Oct 03 '22 15:10

yesnik