栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

CMakeLists.txt常见指令

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CMakeLists.txt常见指令

demo1——单文件

只有一个main.cpp的情况

main.cpp

#include

int main(int argc, char** argv)
{
	std::cout<<"hellosl"< 

CMakeLists.txt

cmake_minimum_required( VERSION 2.8)
project(demo)
add_executable(demo main.cpp)

编译指令:(以下demo将不再提)

mkdir build
cd build
cmake ..
make
demo2——多文件

有main.cpp和pose.h、pose.cpp。

main.cpp

#include
#include"pose.h"
using namespace std;

int main(int argc, char** argv)
{
	for(int i=0;i 

注意:int main(int argc, char** argv)

pose.cpp

#include"pose.h"

int pose()
{
	int a = 6+3;
	return a;
}

pose.h

#ifndef POSE_H_
#define POSE_H_

int pose();
#endif

注意:# ifndef #define #endif使用

CMakeLists.txt

cmake_minimum_required( VERSION 2.8 )
project(pose)

add_executable(pose main.cpp)
add_library(poselib pose.cpp)  # 静态库
add_library(share_pose_lib SHARED pose.cpp)  # 动态库
target_link_libraries(pose poselib)

注意:
1)加上add_library(poselib pose.cpp)该语句后,会在build文件夹下生成libposelib.a静态库。也可以使用,也可使用add_library(poselib STATIC pose.cpp)
2)add_library(share_pose_lib SHARED pose.cpp) # 动态库,会在build文件夹下生成libposelib.so动态库。
3)poselib和share_poselib名称不能相同

demo3——eigen

eigen.cpp

具体代码可参考:https://blog.csdn.net/weixin_41874898/article/details/121254989

CMakeLists.txt

cmake_minimum_required( VERSION 2.8 )
project(eigen_demo)
include_directories("/usr/include/eigen3")
add_executable(eigen_demo eigen.cpp)

eigen是个头文件库,只有h文件,没有cpp文件,在写cmake的时候,只有包含头文件include_directories,不用target_link_libraries。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/457179.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号