码迷,mamicode.com
首页 > 其他好文 > 详细

cmake--生成--静态库

时间:2019-04-13 23:24:34      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:hello   lin   结构   cut   vat   run   bsp   ati   指定   

一, 目录结构

├── CMakeLists.txt
├── include
│   └── static
│   └── Hello.h
└── src
├── Hello.cpp
└── main.cpp

* link:CMakeLists.txt[] - Contains the CMake commands you wish to run
* link:include/static/Hello.h[] - The header file to include
* link:src/Hello.cpp[] - A source file to compile
* link:src/main.cpp[] - The source file with main

二,cmake基本脚本

cmake_minimum_required(VERSION 3.5)

project(hello_library)

# 根据库文件代码生成静态库
add_library(hello_library STATIC src/Hello.cpp)

# 包含指定头文件所在的目录
target_include_directories(hello_library PUBLIC  ${PROJECT_SOURCE_DIR}/include)

# 创建可执行程序

add_executable(hello_binary
src/main.cpp
)

# 链接静态库文件
target_link_libraries( hello_binary PRIVATE hello_library)

三,扩展分析

1.  add_library(hello_library STATIC  src/Hello.cpp)将会创建 libhello_library.a 名称的静态库。

2. 域名关键字

* +PRIVATE+ - the directory is added to this target‘s include directories
* +INTERFACE+ - the directory is added to the include directores for any targets that link this library.
* +PUBLIC+ - As above, it is included int his library and also any targets that link this library.

 

cmake--生成--静态库

标签:hello   lin   结构   cut   vat   run   bsp   ati   指定   

原文地址:https://www.cnblogs.com/svenzhang9527/p/10703401.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!