cmake 学习笔记
来源:互联网 发布:天津大学网络教育专业 编辑:程序博客网 时间:2024/05/22 06:29
Step1: 基本开始
文件结构:
----Tutorial
|----build
|----CMakeLists.txt
|----tutorial.cpp
CMakeLists.txt:
cmake_minimum_required (VERSION 2.6)project (Tutorial)add_executable(Tutorial tutorial.cxx)
tutorial.cpp: 一个计算平方根的例子
// A simple program that computes the square root of a number#include <stdio.h>#include <stdlib.h>#include <math.h>int main (int argc, char *argv[]){ if (argc < 2) { fprintf(stdout,"Usage: %s number\n",argv[0]); return 1; } double inputValue = atof(argv[1]); double outputValue = sqrt(inputValue); fprintf(stdout,"The square root of %g is %g\n", inputValue, outputValue); return 0;}build 目录下cmake .. (cmake 后面是CMakeLists.txt的相对路径,这里是在build上一级目录中,所以是"..")
make
运行build下生成的可执行文件:
./Tutorial 9 (计算9的平方根)版本控制:
文件结构:
----Tutorial
|----build
|----CMakeLists.txt
|----tutorial.cpp
|----Tutorial.h.in
文件结构:
----Tutorial
|----build
|----CMakeLists.txt
|----tutorial.cpp
|----Tutorial.h.in
CMakeLists.txt:cmake_minimum_required (VERSION 2.6)project (cmaketest)# The version number.set (Tutorial_VERSION_MAJOR 1)set (Tutorial_VERSION_MINOR 0) # configure a header file to pass some of the CMake settings# to the source codeconfigure_file ( "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in" "${PROJECT_BINARY_DIR}/TutorialConfig.h" ) # add the binary tree to the search path for include files# so that we will find TutorialConfig.hinclude_directories("${PROJECT_BINARY_DIR}") # add the executableadd_executable(Tutorial tutorial.cpp)Tutorial.h.in
// the configured options and settings for Tutorial#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
tutorial.cpp:
// A simple program that computes the square root of a number#include <stdio.h>#include <stdlib.h>#include <math.h>#include "TutorialConfig.h"int main (int argc, char *argv[]){ if (argc < 2) { fprintf(stdout,"%s Version %d.%d\n", argv[0], Tutorial_VERSION_MAJOR, Tutorial_VERSION_MINOR); fprintf(stdout,"Usage: %s number\n",argv[0]); return 1; } double inputValue = atof(argv[1]); double outputValue = sqrt(inputValue); fprintf(stdout,"The square root of %g is %g\n", inputValue, outputValue); return 0;}
build目录下cmake ..
make
执行:./Tutorial
输出版本信息
./Tutorial Version 2.0
Usage: ./Tutorial number
Step 2: 添加库
阅读全文
0 0
- cmake学习笔记
- cmake 学习笔记(一)
- cmake 学习笔记(二)
- cmake 学习笔记(三)
- cmake 学习笔记(四)
- cmake学习笔记(五)
- cmake 学习笔记(六)
- Cmake学习笔记
- cmake 学习笔记(一)
- cmake 学习笔记(二)
- cmake 学习笔记(三)
- cmake 学习笔记(一)
- CMake 学习笔记
- CMake学习笔记
- cmake 学习笔记
- cmake 学习笔记(二)
- cmake 学习笔记(一)
- cmake 学习笔记(三)
- 设计模式——桥接模式
- eclipse工作空间的删除
- 设计师要失业?阿里AI“鲁班”每秒做8000张海报
- Web前端,大咖问答
- UDP编程
- cmake 学习笔记
- UVa 10368
- 71. Simplify Path (简化路径)
- Composer安装使用
- Android堆叠式布局实现
- eclipse loading org.eclipse 启动无响应 停留在Loading状态
- SSM搭建
- 壕!程序员摆25台iPhone X求婚 闺蜜1人1台
- C语言的下标运算与指针的关系