Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CMake cannot find .so which is symbolic link file

Platform: ubuntu22.04
I’m using cmake to link to a 3rd party library. It looks like:

// Those two files are identical. 
// abc.so is the original file and libabc.so is a copy

// ${shared} is an absolute path
${shared}/libabc.so
${shared}/abc.so

My CMakeLists.txt:

LINK_DIRECTORIES(${shared})

ADD_EXECUTABLE(main ...)

TARGET_LINK_LIBRARIES(main libabc.so)

So far it works fine. You may have noticed that I have ${shared}/libabc.so and ${shared}/abc.so at the same time. They are identical. So I delete libabc.so (abc.so is the original file) and create a link file with
ln -s relative_path/shared/abc.so relative_path/shared/libabc.so.
But I got:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

/usr/bin/ld: cannot find -labc: No such file or directory
collect2: error: ld returned 1 exit status

Why do I get this error when libabc.so did exists?

>Solution :

Unless you ran ln -s shared/abc.so shared/libabc.so from the root directory (with current working directory of shell in root directory), it should have instead been ln -s /shared/abc.so /shared/libabc.so. Same issue: you want absolute paths and not relative paths.

Not sure if this applies or not according to your ${shared} variable, note from the docs for link_directories:

Adds the paths in which the linker should search for libraries. Relative paths given to this command are interpreted as relative to the current source directory

Also, I believe your target_link_libraries(main libabc.so) can be target_link_libraries(main abc), as documented in the target_link_library docs in the "plain library name" form of <item> parameters.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading