use relative at CMake

Hi,

When I want to include dynamic or static libraries, I need to write the full path of it.

How can I include libraries with ../../ notation (relative to where the project is located)?

4 comments
Comment actions Permalink

Hi Lior.

There is a list of useful cmake variables you can use in CMakeLists.txt: https://cmake.org/Wiki/CMake_Useful_Variables. Although for external libraries, you probably might consider using find_package. Also note that if you're linking with your own libraries from the same parent project, you can link by target name, e.g.

add_library(lib1 ...)

add_executable(exe1 ...)

target_link_libraries(exe1 lib1 ...)
0
Comment actions Permalink

Hi Anna,

 

I will make my self clear. When I want to link library I need to write the full path : /home/user/path/to/library.

If I write relative path ../../path/to/library CLion does not find the library.

0
Comment actions Permalink

Lior, while this way of finding libraries is not recommended, it should work, as far as I can tell. Could you please provide the whole CMakeLists.txt and describe your project/library locations?

0
Comment actions Permalink

Anna,

My CMakeLists.txt is attached as image to this message.

The project locations is : ~/ClionProjects/FDR.

All the files located under this path.

Lior

0

Please sign in to leave a comment.