Cannot find -lmysqlclient

I am trying to compile a program in C ++ and use one of the classes. g ++ cannot find libraries, I think. 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 mysql.h needs. This one works fine on my local machine, but refuses to run on the server with an error

 cannot find -lmysqlclient 

I tried to find the libmysqlclient.so files on the server using the find , I don’t think they are there

 uname -a 

shows

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

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

Any help would be greatly appreciated. Thanks.

+8
mysql solaris
source share
4 answers

Regardless of which library packages you think are not installed, you can install using sudo apt-get install . But the problem is to find the correct package name that apt-get can understand. So how to do this ?! just

use the command: sudo apt-cache search <filename>

For example: in this case lmysqlclient

 sudo apt-cache search mysqlclient 

(remember to exclude 'l' from the actual name, i.e. mysqlclient, 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, cannot find lmysqlclient we cannot find lmysqlclient problem cannot find lmysqlclient

so now type: sudo apt-get install libmysqlclient-dev from the interface. Once this is done, try creating the desired file.

+7
source share

Do you have MySQL client libraries? You can find it like

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

Alternatively, you can use the -R flag in the linker to force libmysqlclient to be referenced as

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

Or you can export LD_LIBRARY_PATH_32 or LD_LIBRARY_PATH_64 as

 export LD_LIBRARY_PATH_32=$MYSQL_HOME/lib 

Urko,

+2
source share

Simplification @ SriHariY.S answer-

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

+1
source share

In Ubuntu 18, I used this command to find the name of the required package to fix this error:

 apt search lmysqlclient 

After that, I installed the missing package:

 sudo apt install libmariadbclient-dev-compat 
0
source share

All Articles