CMake and Static Linking

后端 未结 2 683
庸人自扰
庸人自扰 2020-12-04 14:35

I\'m using CMake in a project, and I\'m trying to statically link some libraries. I\'ve set:

set(BUILD_SHARED_LIBS OFF)
set(CMAKE_EXE_LINKER_FLAGS \"-static-         


        
2条回答
  •  长情又很酷
    2020-12-04 15:26

    How do I setup for static linkage using CMake

    Well... you don't :) That's not how CMake works: in CMake, you first find the absolute path of a library, then link to it with target_link_libraries.

    So, if you want to link to a static library, you need to search for that static library:

    find_library(SOMELIB libsomelib.a)
    

    instead of:

    find_library(SOMELIB somelib)
    

提交回复
热议问题