国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

cmake 學習筆記

2019-11-11 04:12:52
字體:
供稿:網(wǎng)友

cmake 學習筆記

測試環(huán)境,Ubuntu 14.04

參考:http://blog.csdn.net/dbzhang800/article/details/6314073


例子1:helloworld

目錄結(jié)構(gòu)如下

.├── 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;}

先創(chuàng)建CMakeLists.txtmain.c這兩個文件,然后新建build目錄,cd到build目錄下,執(zhí)行(cmake 命令后跟一個路徑(..),用來指出 CMakeList.txt 所在的位置。)

cmake ..make

這里寫圖片描述

生成的hello即為可執(zhí)行程序。


例子2: helloworld again !

在main.c 同目錄下增加兩個文件hello.hhello.c

#ifndef _HELLO__#define _HELLO__void hello(const char* name);#endif //_HELLO__#include <stdio.h>#include "hello.h"void hello(const char* name){ printf("hello %s again!/n", name);}#include "hello.h"int main(){ hello("world"); return 0;}

CMakeLists.txt

project(HELLO)set(SRC_LIST main.c hello.c)add_executable(hello ${SRC_LIST})

執(zhí)行cmake的過程同上


例子3:

生成一個庫。

修改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)
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 达州市| 历史| 临洮县| 永州市| 宁德市| 临海市| 宁国市| 手游| 乌拉特后旗| 玛曲县| 将乐县| 淅川县| 名山县| 利川市| 太康县| 松阳县| 沿河| 利津县| 巴林左旗| 包头市| 红河县| 方山县| 彭泽县| 麻江县| 东乌珠穆沁旗| 六枝特区| 嵊州市| 嘉善县| 长丰县| 肇源县| 嵊州市| 抚顺县| 论坛| 南澳县| 江安县| 开化县| 驻马店市| 山阴县| 朝阳县| 准格尔旗| 泗洪县|