Reputation: 28
On GNU/Linux the convention is to pass the name of the library (let's call it foo) to target_link_libraries without the lib prefix (otherwise it tries to link liblibfoo.so). On windows however when I'm asking to link with "foo" it tries to find "foo.lib" which does not exist, as the library is named libfoo.lib. Is there a way to instruct cmake to add the lib prefix, without resorting to yet another if(WIN32) block ?
Upvotes: 0
Views: 2168
Reputation: 66118
Use command find_library for search absolute path to the library. You may specify all possible names of searched library with NAMES
option:
find_library(FOO_LIBRARY NAMES foo libfoo)
Then use result of this command for link with the library:
target_link_libraries(my_exec ${FOO_LIBRARY})
Upvotes: 1