Where is LD_LIBRARY_PATH? how to set the LD_LIBRARY_PATH env variable

environment-variables

I am trying to build a c++ program using Unix.

I got the error

Linking CXX executable ../../bin/ME
/usr/bin/ld: cannot find -lboost_regex-mt

I heard that I just need to set the location of libboost* in my LD_LIBRARY_PATH env variable and then invoke make as I originally did, by typing

-L /usr/lib64 -l boost_regex-mt

or

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64

But where is LD_LIBRARY_PATH? how do I set the LD_LIBRARY_PATH env variable?

Best Answer

how do I set the LD_LIBRARY_PATH env variable?

You already set it when you did this:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64

But that will not solve your problem. $LD_LIBRARY_PATH is consulted at time of execution, to provide a list of additional directories in which to search for dynamically linkable libraries. It is not consulted at link time (except maybe for locating libraries required by the built tools themselves!).

In order to tell the linker where to find libraries at build time, you need to use the -L linker option. You already did that too:

-L /usr/lib64

If you are still getting the error, then you need to make sure that the library is actually there. Do you have a file libboost_regex-mt.so or libboost_regex-mt.a in that (or any) directory? Note that a file like libboost_regex-mt.so.othersuffix doesn't count for this purpose. If you don't have that, then you probably need to install your distribution's development package for this library.

Related Question