Unable to find a shared library in the same directory as CMakeLists.txt


In my source code directory, I have a shared library file called libAlpha.so. Then, in my CMakeLists.txt file, I have:

target_link_libraries(MyProgram Alpha)

However, this gives me the error:

usr/bin/ld: cannot find -lAlpha

If I rename the library file to Alpha.so or lAlpha.so, I get the same error. Similarly, if I instead use the line:

target_link_libraries(MyProgram libAlpha)


target_link_libraries(MyProgram libAlpha.so)

Why can cmake not find this library, even though it is in the same directory as CMakeLists.txt?

Don't use link_directories.

Specify the full path to the library (possibly using ${CMAKE_CURRENT_SOURCE_DIR} if that's where you have it, or use find_library with that path and the name (without lib prefix or extension) for a 'more portable' solution, though something tells me portability is not your concern...