seo站內(nèi)優(yōu)化包括怎么注冊(cè)一個(gè)網(wǎng)站
文章目錄
- 一、概述
- 二、實(shí)戰(zhàn)
- 2.1 內(nèi)部構(gòu)建、外部構(gòu)建
- 2.2 CLion Cmake
一、概述
CMake 是跨平臺(tái)構(gòu)建工具,其通過(guò) CMakeLists.txt 描述,并生成 native 編譯配置文件:
- 在 Linux/Unix 平臺(tái),生成 makefile
- 在蘋(píng)果平臺(tái),可以生成 xcode
- 在 Windows 平臺(tái),可以生成 MSVC 的工程文件
二、實(shí)戰(zhàn)
// file main.cpp
#include <iostream>
int main() {std::cout << "Hello, World!" << std::endl;return 0;
}// file CMakeLists.txt
cmake_minimum_required(VERSION 3.25) # 最低的 CMake 版本
project(hello) # 項(xiàng)目名稱
set(CMAKE_CXX_STANDARD 17) # 編譯使用哪個(gè) C++ 版本
add_executable(hello main.cpp) # add_executable(executable_name ${SRC_LIST}) 可執(zhí)行文件的名字和源文件列表
在目錄下有 main.cpp 和 CMakeLists.txt 兩個(gè)文件,執(zhí)行 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: /cppcodes/HelloWorld
此時(shí)會(huì)生成 CMakeFiles、CMakeCache.txt、cmake_install.cmake、Makefile 等文件,執(zhí)行 make 即可使用 Makefile 文件(make VERBOSE=1 可看到詳細(xì)過(guò)程):
Scanning dependencies of target HelloWorld
[ 50%] Building CXX object CMakeFiles/HelloWorld.dir/main.cpp.o
[100%] Linking CXX executable HelloWorld
[100%] Built target HelloWorld
然后生成了可執(zhí)行文件,執(zhí)行 ./HelloWorld 即可
2.1 內(nèi)部構(gòu)建、外部構(gòu)建
內(nèi)部構(gòu)建:在項(xiàng)目?jī)?nèi)部,有CMakeList.txt的地方,直接cmake .,比如我們前面講的簡(jiǎn)單案例都是最簡(jiǎn)單的內(nèi)部構(gòu)建. 結(jié)果你也看見(jiàn)了,就是在項(xiàng)目下面生成了很多的臨時(shí)文件。
外部構(gòu)建:不直接在項(xiàng)目下面運(yùn)行cmake, 而是自己建立一個(gè)接受cmake之后的臨時(shí)文件的文件夾,然后再該文件夾下面調(diào)用cmake <CMakeList_path> 來(lái)構(gòu)建.運(yùn)行 make 構(gòu)建工程,就會(huì)在當(dāng)前目錄(build 目錄)中獲得目標(biāo)文件 hello。上述過(guò)程就是所謂的out-of-source外部編譯,一個(gè)最大的好處是,對(duì)于原有的工程沒(méi)有任何影響,所有動(dòng)作全部發(fā)生在編譯目錄。示例如下:
# tree
-- build # 構(gòu)建結(jié)果的文件夾
-- CMakeLists.txt
-- main.cpp# 在 build 文件夾中執(zhí)行 make .. 即可生成結(jié)果
2.2 CLion Cmake
Clion CMake tutorial