How can I find a library name of .so file?

为君一笑 提交于 2019-12-01 08:15:30

问题


For example, I have libprofiler.so file. How can I get name of this shared object like this:

getname /usr/lib/libprofiler.so

I want to do it because it is required for CMakeLists.txt in

target_link_libraries(MyProject name_of_library)

回答1:


Do the following steps to link an existing lib to your target:

  1. Inform you which lib do you need: here profiler.
  2. Build the name of the lib. CMake does not really needs this but it is worth to know: Example on Unix/Linux lib + NAME + [.so|.a] [VERSION]. Here: libprofiler.so.
  3. In your CMakeLists.txt:

    find_library(LIB_PROFILER NAMES profiler libprofiler.so libprofiler.so.V123)
    add_executable(MyApp ${SOURCES})
    target_link_libraries(MyApp ${LIB_PROFILER})
    

    The code above tries to find a lib and checks the following name profiler, libprofiler.so and libprofiler.so.V123. If found, the variable LIB_PROFILER points to the lib file. Use the variable as one of the files linked to your target.

In your code, you also missed the ${} around the variable.



来源:https://stackoverflow.com/questions/40342705/how-can-i-find-a-library-name-of-so-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!