Geonju Kim
Geonju Kim

Reputation: 31

Use target_link_libraries to libraries not start with lib*

I am trying to link my program(hello) with a special library(/path/abc.so) that not starts with 'lib'.

Here is my CMakeLists.txt

add_executables(hello hello.c)

target_link_libraries(hello /path/abc.so)

It works fine, but is there any other way to avoid this full path(/path/abc.so) things? I don't want to make symlink of abc.so or modify abc.so itself.

Upvotes: 3

Views: 1115

Answers (1)

ErniBrown
ErniBrown

Reputation: 1372

Probably your best option is not to link directly the library, but use imported targets: You can have your library target as

add_library(ABC SHARED IMPORTED)
set_target_properties(ABC PROPERTIES
            IMPORTED_LOCATION path/to/library/abc.so
            INTERFACE_INCLUDE_DIRECTORIES path/to/include
            )

Then you can link it as a target:

target_link_libraries(hello ABC)

The next step would be to have a library find module, or config module, so you don't define full path in your CMakeLists.txt, but search for the library, or just include a .cmake file with all of the paths.

Have a look HERE and HERE

Upvotes: 2

Related Questions