CMake创建和使用静态链接库

生成静态库
cmake_minimum_required(VERSION 2.8)
project(myprj)

set(CMAKE_CXX_FLAGS "-fpermissive")
set(CMAKE_BUILD_TYPE "Debug")

include_directories(./)
include_directories(./MiscLib/)
FILE(GLOB SRC "./*.cpp")
FILE(GLOB MISC_SRC "./MiscLib/*.cpp")

add_library(mylib STATIC  ${SRC} ${MISC_SRC})
调用静态库,需要保证*.h文件都被拷贝过来了
cmake_minimum_required(VERSION 2.8)
project(MyPrj_2)
set(CMAKE_CXX_FLAGS "-fpermissive")
set(CMAKE_BUILD_TYPE "Debug")
include_directories(./)
include_directories(./inc)
include_directories(./MiscLib/)
add_executable(main main.cpp)
target_link_libraries(main ${CMAKE_SOURCE_DIR}/libmylib.a)

你可能感兴趣的:(编程相关技术)