參考《cmake教程》第9講:
目錄樹(沒有編譯,所以build資料夾為空)
)## 方法1
# 使用include_directories
()新增外部標頭檔案位址
# 使用target_link_libraries
()鏈結共享庫
# include_directories(/usr/include)
# add_executable(curltest main.c)
# target_link_libraries(curltest curl)
## 方法2 使用cmake提供的findcurl模組
# 系統預定義變數 _found,
_include_dir,
_library
add_executable
(curltest main.c)
find_package
(curl)
if(curl_found)
include_directories($)
target_link_libraries
(curltest $
)else
(curl_found)
message
(fatal_error "curl library not found! 2020.4.30"
)endif
(curl_found)
src/main.c
#include
#include
#include
#include
file *fp;
intwrite_data
(void
*ptr, size_t size, size_t nmemb,
void
*stream)
intmain()
目錄樹cmake/findhello.cmake
find_path
(hello_include_dir hello.h /usr/include/hello
/usr/local/include/hello)
find_library
(hello_library names hello path /usr/lib /usr/local/lib)
if(hello_include_dir and hello_library)
set(hello_found true)
endif
(hello_include_dir and hello_library)
if(hello_found)
if(not hello_find_quietly)
message
(status "found hello: $"
)endif
(not hello_find_quietly)
else
(hello_found)
if(hello_find_required)
message
(fatal_error "could not find hello library"
)endif
(hello_find_required)
endif
(hello_found)
message
(status "run findhello.cmake success!"
)
cmakelists.txt
cmake_minimum_required
(version 2.8
)project
(hello_use_module)
set(cmake_module_path $
/cmake)
add_subdirectory
(src)
src/cmakelists.txt
cmake_minimum_required
(version 2.8
)find_package
(hello)
if(hello_found)
add_executable
(hello main.c)
include_directories($)
target_link_libraries
(hello $
)endif
(hello_found)
src/main.c
#include
intmain()
CMake 模組的使用和自定義模組
如果程式中使用了外部庫,事先並不知道它的標頭檔案和鏈結庫的位置,就要給出標頭檔案和鏈結庫的查詢方法,並將他們鏈結到程式中。find package major.minor quiet no module required components componets.1 find package 的查詢...
CMake 模組的使用和自定義模組
如果程式中使用了外部庫,事先並不知道它的標頭檔案和鏈結庫的位置,就要給出標頭檔案和鏈結庫的查詢方法,並將他們鏈結到程式中。find package major.minor quiet no module required components componets.1 find package 的查詢...
python from import 自定義模組
from douban250.items import douban250item python import 自定義模組 1 主程式與模組程式在同一目錄下 如下面程式結構 src mod1.py test1.py 若在程式test1.py中匯入模組mod1,則直接使用 import mod1或fr...