Including shared libraries (.so) with CMake

I am trying to include different types of libraries in CMake.

  • .a
  • .dylib
  • .so

Finally, I got both .a and .dylib to work with this code.

 find_library(libname NAMES libcef.dylib PATHS ${libname_PATH}) 

along with this, under i add_executable to initialize all my files for assembly.

 target_link_libraries(${PROJECT_NAME} ${libname}) 

However, I tried using the same code in the .so file, and it does not seem to work.

I get this expression from cmake when I try to create.

 Target "project name" links to item -- path of file -- which is a full-path but not a valid library file name. 

I'm not sure if this is the correct way to handle .so files, or maybe I don’t even understand what .so . Any input and / or clarification would be greatly appreciated.

edit:

THEORY - My theory is that it does not have a library name before the name of the library name, which is called ffmpegsumo.so. However, when I try to rename it, the file name still saves the variable name very strange.

+4
source share
2 answers

The same should work with .so files, just make sure that the .so file is present in the ${libname_PATH} that you specified.

find_library handles all types (.a / .so / .dylib / .dll) equally. The problem may be as follows

- the path is not configured correctly
- error due to absolute path
-.so no
- If the error is related to the assembly (and not just to the configuration), so it may be damaged, try replacing it

- Your library does not look valid.

+1
source

Shared libraries are linked dynamically. This means that your OS will automatically search and download .so files when the time comes to launch the application. You just need to give cmake the name of the library, and the OS will take care of the rest.

For example, if you want to set a link to a dynamic library for libSDL.so, you simply say: target_link_libraries(${PROJECT_NAME} SDL)

As a health check, your linker will look like this to make sure that the SDL library exists on your computer. This is why you can get a binding error if this library is not available during the link, even if it is a truly dynamic library.

0
source

Source: https://habr.com/ru/post/1500816/


All Articles