16

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.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
K_U
  • 15,832
  • 8
  • 26
  • 29

4 Answers4

15

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.

Swaps
  • 1,450
  • 24
  • 31
Sri Hari Y.S
  • 151
  • 1
  • 2
4

Simplifying @SriHariY.S's answer-

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

Swaps
  • 1,450
  • 24
  • 31
3

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,

Perry
  • 11,172
  • 2
  • 27
  • 37
itilys
  • 186
  • 4
3

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
yesnik
  • 4,085
  • 2
  • 30
  • 25
  • I tried to run `sudo /usr/share/one/install_gems` while installing Opennebula and I run in this issue. But when I installed `sudo apt install libmariadbclient-dev-compat` it has fixed the problem in Ubuntu Live Server 18.04. – b00r00x0 Dec 11 '19 at 19:42