广西网站建设价格多少,网网站建设的公司,备案做电影网站吗,关于做女装的网站概述
cmake是一种跨平台编译工具#xff0c;除了可以编译c#xff0c;c代码也可以编译其他语言的代码#xff0c;其主要就是通过cmake执行CMakeLists.txt从而生成Makefile。下面就自己了解到的简单的一点知识#xff0c;做以记录。更多可查看官网#xff1a;https://cmak…概述
cmake是一种跨平台编译工具除了可以编译cc代码也可以编译其他语言的代码其主要就是通过cmake执行CMakeLists.txt从而生成Makefile。下面就自己了解到的简单的一点知识做以记录。更多可查看官网https://cmake.org。
cmake简单使用
创建项目文件夹。 在终端输入指令mkdir testCmake-helloworld创建项目文件及CMakeLists.txt。 在终端输入 cd testCmake-helloworld touch CMakeLists.txt vim main.cpp 打开main.cpp后在其中写入如下内容 main.cppmain.cpp
#include iostreamusing namespace std;int main(int argc,char*argv[])
{couthello world!!endl;return 0;
}保存后退出。 终端输入vim CMakeLists.txt 向CMakeLists.txt写入如下内容
cmake_minimum_required(VERSION 2.8)
project(hello)
add_executable(hello main.cpp)保存退出查看当前的文件列表 $ ls CMakeLists.txt build-hello-cmake main.cpp 可以看到有两个文件CMakeLists.txt 和main.cpp一个文件夹build-hello-cmake此时可以进入到构建目录build-hello-cmake中输入下述指令
cmake ..终端会显示如下
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):Compatibility with CMake 2.8.12 will be removed from a future version ofCMake.Update the VERSION argument min value or use a ...max suffix to tellCMake that the project does not need compatibility with older versions.-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/admin/Program/testCmake-helloworld/build-hello-cmake接着终端输入
make终端显示如下
[ 50%] Building CXX object CMakeFiles/hello.dir/main.cpp.o
[100%] Linking CXX executable hello
[100%] Built target hello此时构建完成在目录build-hello-cmake中生成可执行程序hello。当前路径下执行下述指令
# admin bogon in ~/Program/testCmake-helloworld/build-hello-cmake [17:21:33]
$ ./hello
hello world!!会输出程序的运行结果。 上述是cmake执行构建的过程总体来说就是下列指令
mkdir 构建目录名
cd 构建目录名
cmake CMakeLists.txt所在的路径
make 其构建项目最常用的四句指令就是上述所写。首先在项目目录下创建一个空文件夹作为构建目录即mkdir 构建目录名;然后进入构建目录即cd 构建目录名接下来执行cmake,但是在cmake的后面需要指明CMakeLists.txt所在的路径最后执行make指令整个项目生成可执行程序。 当不在构建目录里执行cmake时可以按照下述方法来执行cmake:
admin bogon in ~/Program/testCmake-helloworld [17:31:29]
$ cmake -S ./ -B ./build-hello-cmake
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):Compatibility with CMake 2.8.12 will be removed from a future version ofCMake.Update the VERSION argument min value or use a ...max suffix to tellCMake that the project does not need compatibility with older versions.-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/admin/Program/testCmake-helloworld/build-hello-cmake
其中-S指明了源文件所在的路径-B指明了构建生成的文件所在的路径。 这样就可以在非构建目录下执行cmake但生成的文件依旧存入到构建目录中。同样接下来也在项目目录下使用指令make,指令如下
# admin bogon in ~/Program/testCmake-helloworld [17:33:09]
$ make -C ./build-hello-cmake
[ 50%] Building CXX object CMakeFiles/hello.dir/main.cpp.o
[100%] Linking CXX executable hello
[100%] Built target hellomake指令中-C指明了生成可执行文件所在的路径。 以上仅供参考。