use relative at CMake


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)?

Comment actions Permalink

Hi Lior.

There is a list of useful cmake variables you can use in CMakeLists.txt: 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 ...)
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.

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?

Comment actions Permalink


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

The project locations is : ~/ClionProjects/FDR.

All the files located under this path.



Please sign in to leave a comment.