測試環境,Ubuntu 14.04
參考:http://blog.csdn.net/dbzhang800/article/details/6314073
目錄結構如下
.├── build├── CMakeLists.txt└── main.c1 directory, 2 files其中CMakeLists.txt
PRoject(HELLO)set(SRC_LIST main.c)add_executable(hello ${SRC_LIST})message(${PROJECT_SOURCE_DIR})message(${PROJECT_SOURCE_DIR})message(${PROJECT_SOURCE_DIR})main.c
#include<stdio.h>int main(){ printf("helloworld/n"); return 0;}先創建CMakeLists.txt
和main.c
這兩個文件,然后新建build目錄,cd到build目錄下,執行(cmake 命令后跟一個路徑(..),用來指出 CMakeList.txt 所在的位置。)
生成的hello即為可執行程序。
在main.c 同目錄下增加兩個文件hello.h
、hello.c
CMakeLists.txt
project(HELLO)set(SRC_LIST main.c hello.c)add_executable(hello ${SRC_LIST})執行cmake的過程同上
生成一個庫。
修改CMakeLists.txt
project(HELLO)set(LIB_SRC hello.c)set(APP_SRC main.c)add_library(libhello ${LIB_SRC})add_executable(hello ${APP_SRC})target_link_libraries(hello libhello)新聞熱點
疑難解答