CMake 学习笔记 —— 进阶
2019獨角獸企業重金招聘Python工程師標準>>>
HelloWorld
HelloWorld ---> CMakeLists.txt
project(Hello)
add_subdirectory(src bin)
src ---> CMakeLists.txt
add_executable(hello main.c)
add_subdirectory用法:
add_subdirectory(source_dir [binary_dir] [exclude_from_all])
srouce_dir 源文件子目錄
binary_dir 中間二進制和目標二進制存放位置
exclude_from_all 將這個目錄從編譯過程中排除
set(executable_output_path ${project_binary_dir}/bin)
set(library_output_path ${project_binary_dir}/lib)
構建動態庫
add_library(libname [SHARED | STATIC | MODULE] [EXCLUDE_FROM_ALL] ? source1 source2 ... sourceN)
不需要寫全libhello.so ,只需要填寫hello即可,cmake系統會自動生成libhello.x
類型有三種:
SHARED 動態庫
STATIC 靜態庫
module 在使用dyld的系統有效,如果不支持dyld,則當作shared對待
導入頭文件
include_directories(/usr/include/hello)
添加共享庫
link_directories ?添加非標準庫搜索路徑?
target_link_libraries 添加需要連接的共享庫
例如:
target_link_libraries(main libhello.so)
target_link_libraries(main libhello.a)
轉載于:https://my.oschina.net/fonddream/blog/505341
總結
以上是生活随笔為你收集整理的CMake 学习笔记 —— 进阶的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关闭IPV6 备忘
- 下一篇: Android读写assets、raw、