How to include C static libraries in CMAKE project on MAC OS X

后端 未结 2 1528
猫巷女王i
猫巷女王i 2021-01-16 10:19

I am trying to learn Core Foundation with C/C++. I use JetBrains CLion that uses CMAKE.

The problem is - I dunno how to include proper static libraries in C/C++ Make

相关标签:
2条回答
  • 2021-01-16 11:07

    Finally resolved.

    Thanks to this resource: http://raycast.net/clion-multiple-binaries

    This is how my CMAKE file looks like and everything links:

    cmake_minimum_required(VERSION 2.8.4)
    project(test001)
    
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    
    set(SOURCE_FILES main.cpp)
    
    find_library(corefoundation_lib CoreFoundation)
    find_library(cfnetwork_lib CFNetwork)
    
    set(frameworks
        ${cfnetwork_lib}
        ${corefoundation_lib})
    
    add_executable(test001 ${SOURCE_FILES})
    target_link_libraries(test001 ${frameworks})
    
    0 讨论(0)
  • 2021-01-16 11:12

    I'm not 100% sure if this is what you ment but you link C static libraries by giving -llibrary flag to your compiler where the name of the library file is liblibrary.a. If the library isn't in some default library location (idk what it is for mac) you can specify the path with -L flag.

    0 讨论(0)
提交回复
热议问题