libraries not found in c++ code using a 3rd party header file

709 Views Asked by At

I am getting a error when I try to compile some c++ code using the olcPixelGameEngine as a header file, the error is -

/usr/bin/ld: cannot find -lGL
/usr/bin/ld: cannot find -lpng
1

There are 1 best solutions below

1
On

Depending on the code being compiled, the error message may look like:

/usr/bin/ld: cannot find -lc

/usr/bin/ld: cannot find -lltdl

/usr/bin/ld: cannot find -lXlst

The xxx represents the name of the library, for example, libc.so, libltdl.so, libXtst.so. The naming rule is: lib + library name (i.e. xxx) + .so.

There are 3 possible reasons for such error to occur:

  1. The lib is not installed in the system;
  2. Incorrect version of the installed lib;
  3. Incorrect symbolic link for the lib (.so file). The link is not linked to the correct .so file.

Solutions:

  1. Check whether the symbolic link is correctly linked to the .so file in /usr/lib and correct any incorrect link.

For example,

If the error message "/usr/bin/ld: cannot find -lXlst" is caused by incorrect symbolic link, issue the commands below to correct it.

cd /usr/lib

ln -s libXtst.so.6 libXtst.so

  1. If the problem is not caused by incorrect symbolic link, then it's likely caused by missing lib. In this case, missing lib needs to be installed.

For example,

If the error message "/usr/bin/ld: cannot find -lXlst" is caused by missing "libXtst.so" under "/usr/lib", issue the command below to install it.

apt-get install libxtst-dev

Additional note on how to install the missing lib.

  1. Identify the missing lb

          Error Message                             Missing lib
    

/usr/bin/ld: cannot find -lc ---------------------------------------------------->libc

/usr/bin/ld: cannot find -lltdl ---------------------------------------------------->libltdl

/usr/bin/ld: cannot find -lXlst ----------------------------------------------------> libXtst

  1. Search for the missing lib

    apt-cache search libc-dev

    apt-cache search libltdl-dev

    apt-cache search libXtst-dev

  2. Install the missing lib.

please refer below link. this might help.

http://wei48221.blogspot.com/2017/08/linux-how-to-solve-problem-of-usrbinld.html