随想录(cmake编译)
编译 CMake 随想录
2023-09-27 14:27:11 时间
【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】
在linux下面,编译软件有很多的方法。一般来说,有这么几种。第一,自己写makefile,这种情况一般适用于工程比较简单的项目,结构不复杂,同时也能满足需求;第二,利用autoconf、automake生成makefile。目前来说,大多数开源项目都是采用这种编译方法。这种方法用起来也比较简单,常见的操作就是 ./configure && make && make install。第三,就是cmake这种,不用自己写makefile,只需要配置一下脚本,自动生成makefile。第四种不太常见,scons创建,和第三种差不多,但是比第三种还要简单,一两行脚本文件就能完成所有的操作。
既然今天说的是cmake,那么我们说明一下如何利用cmake创建makefile编译。
1) 安装cmake。
2) 创建prj目录,cd到prj目录下面。
3) 拷贝两个文件过来,比如说add.c和main.c,这是比较常见的情况,即多个文件生成一个执行文件。
4) 创建CMakeLists.txt文件,输入下面的内容,
project(HELLO)
set(SRC_LIST main.c add.c)
add_executable(hello ${SRC_LIST})
5) 输入cmake .命令,注意后面的点号。
feixiaoxingdeMacBook-Pro-2:cmake feixiaoxing$ cmake .
-- The C compiler identification is AppleClang 7.0.0.7000176
-- The CXX compiler identification is AppleClang 7.0.0.7000176
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/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: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/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: /Users/feixiaoxing/Desktop/cmake
6) 此时makefile已经生成,直接make即可。
feixiaoxingdeMacBook-Pro-2:cmake feixiaoxing$ make
Scanning dependencies of target hello
[ 33%] Building C object CMakeFiles/hello.dir/main.c.o
[ 66%] Building C object CMakeFiles/hello.dir/add.c.o
[100%] Linking C executable hello
[100%] Built target hello
相关文章
- 路由器逆向分析------MIPS交叉编译环境的搭建(Buildroot)
- vs code编译
- GCC/Cmake,预处理,编译,汇编,链接
- C/C++静态库编译报错(/usr/bin/ld:cannot find -lpthread,/usr/bin/ld:cannot find -lc)
- 利用CMake编译OpenCV-4.1.2源码,使其可以在VS2012下进行图像处理开发的记录(因缺少OpenBLAS未成功)
- 不用CMake编译查询OpenCV函数、类定义等的方法(全文搜索-所有文档搜索指定内容神器:CJC超级硬盘快搜索和AnyTXT Searcher)
- 《编译与反编译技术实战 》一 第1章 实践的环境与工具
- CMake 生成 VS2022 编译CVUI报错MSB307
- 学习cmake从成功编译一个小程序开始
- Xamarin.Android编译提示找不到mscorlib.dll.so文件
- C编译:make和cmake的区别
- android在ubuntu中编译为.apk资料
- 如何单独编译Android源代码中的模块
- 《OpenGL ES应用开发实践指南:Android卷》——第3章 编译着色器及在屏幕上绘图
- 国产计算框架Mindspore1.3.0 gpu源代码中的cmake文件存在问题(bug),openmpi的url错误,导致不能正常编译——成功解决mindspore-gpu-1.3.0版本不能从源代码中编译的问题
- CMake: (一) arm浮点编译参数
- Cmake,链接一个外部(也可能是第三方,也可能是自己编译的)库
- 编译(- c)某个源文件生成目标文件只需要路径有调用函数的头文件,链接(- o)成可执行文件需要加上实现函数的目标文件
- 入门cmake,窥探编译过程
- (转+原)VC编译错误:uafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMT.lib(new.obj) 中定义
- 编译原理实验1——词法分析程序设计原理与实现