[CMake] Testing shared library

"Flávio P. Duarte" fduarte at gisplan.com.br
Tue Jul 25 14:19:40 EDT 2006


It looks like CMake is prependind LD_LIBRARY_PATH before ../src and in
LD_LIBRARY_PATH there is an older version of mylib.
The CMake command line looks like:
/usr/bin/c++   -g -Wall   -fPIC -L/home/user/lib/
"CMakeFiles/test1.dir/obj1.o" "CMakeFiles/test1.dir/obj2.o"   -o test1
-rdynamic -L/home/user/test/src
 I think the first -L is being added to CMake to correspond to
LD_LIBRARY_PATH environment variable. The easiest solution would be get
rid of LD_LIBRARY_PATH, but I consider it as a last option. And if the
first -L corresponds to LD_LIBRARY_PATH, it might be a bug. People will
not be able to test their libraries without changing this variable first.
	As an alternative, I thought change the command line, but I open to
suggestions.

Flavio


Brad King wrote:
> Flávio P. Duarte wrote:
>> Hi,
>>   I am trying to test a shared library using cmake. In my top level
>> directory, I have the source directory (src), which contains the source
>> files to build the library, and a test directory (test), which contains
>> the source files to build the binaries that will be used to test the
>> shared library. The problem is the binaries in the test diretory are not
>> being compiled properly, i. e., they are not being linked against the
>> shared library in the src directory. In autotools, the shared library
>> was added as one obj file, like:
>> g++ -o test1 obj1.o obj2.o ../src/libmylib.so
>>   I was not able to configure CMake to produce a similar command line.
>> How can I achieve this ?
> 
> CMake will generate a command line like
> 
>   g++ -o test1 obj1.o obj2.o -L../src -lmylib
> 
> What problem are you having with this version?
> 
> Note also that when linking to another target in the same project with
> TARGET_LINK_LIBRARIES you do not need to add the LINK_DIRECTORIES
> explicitly.
> 
> -Brad
> 
> 



More information about the CMake mailing list