CMake简单工程
作者:三味书屋 来源: 2022/6/22 9:06:01

hello-world.cpp:

#include <cstdlib>
#include <iostream>
#include <string>

std::string say_hello()
{
	return std::string("hello word!");
}
int main(int argc,char** argv)
{
	std::cout<<say_hello()<<std::endl;
	return EXIT_SUCCESS;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)//指定CMake最低版本3.5

project(hello-world-01 LANGUAGES CXX)//指定项目名称hello-world-01  使用语言是C++

SET(CMAKE_CXX_COMPILER /usr/bin/g++)//指定C++是编辑器原因查看 add_executable(hello-world hello-world.cpp)//将源文件hello-world.cpp生成名为hello-world的可执行程序

cd进入output文件夹,依次执行命令

cmake..//在当前目录的上层目录中查找CMakeLists.txt,并在当前目录中构建工程

make

./hello-world   //执行程序

output目录如下:

称      呼:
联系方式:
您的评论:
技术支持:l.w.dong@qq.com www.luweidong.cn
广州市   wx:lwdred
Copyright © 2014 三味书屋 All Rights Reserved
技术支持:l.w.dong@qq.com  sitemap xml  sitemap html

粤公网安备44010602011869号

粤ICP备13031080号-1