[CMake] Efficient linking to libraries(static and dynamic)

Andreas Pakulat apaku at gmx.de
Wed Feb 11 01:42:10 EST 2009


On 11.02.09 11:31:18, ankit jain wrote:
> Hi all,
> 
> I have folder f1 having csome cpp files. structure is like this:
> f1
> ....c1.cpp
> ....c2.cpp
> 
> now i create an executable for it as
> add_executable(myexe c1.cpp c2.cpp)
> 
> the path of f1 folder is /home/ankit/mycode/f1
> now i want to link myexe to a library lib.so and lib1.a which are not in
> this folder but resides in other folder suppose in lib whose path is
> something like this:
> 
> /home/ankit/mycode/lib/lib.so
> /home/ankit/mycode/lib/lib1.a
> 
> How to do achieve this linkage so that no unref came.
> Right now iam doing it usinmg target_link_libraries by giving the entire
> path somthing like this:
> 
> target_link_libraries(myexe /home/ankit/mycode/lib/lib.so
> /home/ankit/mycode/lib/lib1.a)
> 
> but it gives some unrefs. i dont know why.

You're doing it correctly, if you still get undefined references you're
missing yet another library. For example lib.so might need you to link to
more libraries if it exposes some of the symbols from those.

For better cross-platform working of your project you should look into
the find_library command to avoid hardcoding the path of the libraries in
your CMakeLists.txt.

Andreas 

-- 
You will remember something that you should not have forgotten.


More information about the CMake mailing list