av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

Linux下CMake使用實例

CMake是一個跨平臺的安裝(編譯)工具,可以用簡單的語句來描述所有平臺的安裝(編譯過程)。他能夠輸出各種各樣的makefile或者project文件,能測試編譯器所支持的C++特性,類似UNIX下的automake。

站在用戶的角度思考問題,與客戶深入溝通,找到富川網(wǎng)站設(shè)計與富川網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名注冊虛擬主機、企業(yè)郵箱。業(yè)務(wù)覆蓋富川地區(qū)。

一、單文件目錄

1. 編輯C程序文件,命名為main.c

#include  

int main(void) {
   printf("Hello World.\n");
   return 0;
}

2. 編寫CMakeLists.txt文件,保存在main.c同路徑下

#Minimum required CMake Version
cmake_minimum_required(VERSION 3.6.1)

#Project Name
project(hello)
#把當(dāng)前目錄(.)下所有源代碼文件和頭文件加入變量SRC_LIST
AUX_SOURCE_DIRECTORY(. SRC_LIST)
#生成應(yīng)用程序hello(在windows下生成hello.exe)
ADD_EXECUTABLE(hello ${SRC_LIST})

3. 運行cmake命令生成MakeFile,再運行make命令生成hello可執(zhí)行程序(為防止文件混亂,可建立build目錄,在此目錄下運行cmake命令)

mgh@mgh-OptiPlex-5050:~/桌面/cmake_test/test2/build$ cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mgh/桌面/cmake_test/test2/build
mgh@mgh-OptiPlex-5050:~/桌面/cmake_test/test2/build$ make
Scanning dependencies of target hello
[ 50%] Building C object CMakeFiles/hello.dir/test1.c.o
[100%] Linking C executable hello
[100%] Built target hello
mgh@mgh-OptiPlex-5050:~/桌面/cmake_test/test2/build$ ./hello
Hello World.

二、多文件目錄

1. 目錄結(jié)構(gòu)

mgh@mgh-OptiPlex-5050:~/桌面/cmake_test$ tree test
test
├── CMakeLists.txt
├── print
│   ├── CMakeLists.txt
│   ├── print.c
│   └── print.h
└── test.c

2. 編輯C程序文件

test.c

#include  
#include "print/print.h"

int main(void) {
   print();
   return 0;
}

print.h

#ifndef PRINT_H
#define PRINT_H

extern void print();

#endif

print.c

#include  

extern void print(){
   printf("Hello World.\n");
}

3. 編輯CMakeLists.txt文件

這種多目錄的情況,需要在每個源文件路徑中分別編寫CMakeLists.txt文件,對應(yīng)這個例子,需要在test根目錄和print目錄下編寫CMakeLists.txt文件。

為了方便,我們可以先將print目錄里的文件編譯成靜態(tài)庫再由main函數(shù)調(diào)用。

test目錄下的CMakeLists.txt文件:

#Minimum required CMake Version
cmake_minimum_required(VERSION 3.6.1)

#Project Name
project(hello)

#當(dāng)前目錄下所有源文件保存到SRC_LIST中
AUX_SOURCE_DIRECTORY(. SRC_LIST)

#添加print子目錄
add_subdirectory(print)

#指定生成目標(biāo)
ADD_EXECUTABLE(hello ${SRC_LIST})

#添加鏈接庫
target_link_libraries(hello printFunc)

print目錄下的CMakeLists.txt文件:

#當(dāng)前目錄下所有源文件保存到SRC_LIST中
AUX_SOURCE_DIRECTORY(. SRC_LIB)

#生成鏈接庫
ADD_LIBRARY(printFunc ${SRC_LIB})

4. 編譯運行

mgh@mgh-OptiPlex-5050:~/桌面/cmake_test/test/build$ cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mgh/桌面/cmake_test/test/build
mgh@mgh-OptiPlex-5050:~/桌面/cmake_test/test/build$ make
Scanning dependencies of target printFunc
[ 25%] Building C object print/CMakeFiles/printFunc.dir/print.c.o
[ 50%] Linking C static library libprintFunc.a
[ 50%] Built target printFunc
Scanning dependencies of target hello
[ 75%] Building C object CMakeFiles/hello.dir/test.c.o
[100%] Linking C executable hello
[100%] Built target hello
mgh@mgh-OptiPlex-5050:~/桌面/cmake_test/test/build$ ./hello
Hello World.

當(dāng)前標(biāo)題:Linux下CMake使用實例
標(biāo)題來源:http://uogjgqi.cn/article/cohjjpi.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流