cmake 单个目录多个文件的情况
参考:https://www.hahack.com/codes/cmake/#
源文件一共有三个:main.cpp、MathFunctions.h、MathFunctions.cpp
文件内容分别如下:
main.cpp
#include <stdio.h>
#include <stdlib.h>
#include "MathFunctions.h" int main(int argc, char *argv[])
{
if (argc < ){
printf("Usage: %s base exponent \n", argv[]);
return ;
}
double base = atof(argv[]);
int exponent = atoi(argv[]);
double result = power(base, exponent);
printf("%g ^ %d is %g\n", base, exponent, result);
return ;
}
MathFunctions.h
#ifndef POWER_H
#define POWER_H extern double power(double base, int exponent); #endif
MathFunctions.cpp
/**
* power - Calculate the power of number.
* @param base: Base value.
* @param exponent: Exponent value.
*
* @return base raised to the power exponent.
*/
double power(double base, int exponent)
{
int result = base;
int i; if (exponent == ) {
return ;
} for(i = ; i < exponent; ++i){
result = result * base;
} return result;
}
CMakeLists.txt内容如下:
# CMake 最低版本号要求
cmake_minimum_required (VERSION 2.8) # 项目信息
project (Demo2) # 查找目录下的所有源文件
# 并将名称保存到 DIR_SRCS 变量
aux_source_directory(. DIR_SRCS) # 指定生成目标
add_executable(Demo ${DIR_SRCS})
这里需要学习的是使用变量获取目录下的所有源文件:
aux_source_directory(. DIR_SRCS)
# 指定生成目标
add_executable(Demo ${DIR_SRCS})
编译及执行结果如下:
wmz@ubuntu:~/Desktop/testcmake1$ cmake .
-- The C compiler identification is GNU 5.4.
-- The CXX compiler identification is GNU 5.4.
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /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: /usr/bin/c++
-- Check for working CXX compiler: /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: /home/wmz/Desktop/testcmake1
wmz@ubuntu:~/Desktop/testcmake1$ make
Scanning dependencies of target Demo
[ %] Building CXX object CMakeFiles/Demo.dir/MatnFunctions.cpp.o
[ %] Building CXX object CMakeFiles/Demo.dir/main.cpp.o
[%] Linking CXX executable Demo
[%] Built target Demo
wmz@ubuntu:~/Desktop/testcmake1$ ls
CMakeCache.txt CMakeLists.txt Makefile
CMakeFiles Demo MathFunctions.h
cmake_install.cmake main.cpp MatnFunctions.cpp
wmz@ubuntu:~/Desktop/testcmake1$ ./Demo
^ is
cmake 单个目录多个文件的情况的更多相关文章
- 51-du 显示关于目录层次结构或文件磁盘使用情况的信息
显示关于目录层次结构或文件磁盘使用情况的信息 du [options] [path-list] 参数 不带任何参数的du将显示工作目录及其子目录磁盘使用情况的信息,path-list指定要获取磁盘占用 ...
- git clone 指定的单个目录或文件夹
git clone 指定的单个目录或文件夹 针对自己的项目 方法一 基于sparse clone变通方法 创建一个空仓库 拉取远程仓库信息 开启 sparse clone 设置过滤 更新仓库 创建空仓 ...
- cmake指定程序输出目录和库文件输出目录和拷贝文件
概述 本文样式环境: win10+cmake 3.18 本文将介绍使用CMAKE配置项目输出目录和 LIbrary项目的输出目录 本文将介绍 cmake的file函数的基础用法之拷贝文件 重点, 这些 ...
- 利用WatchService监控C盘根目录下的文件情况
public static void main(String[] args) throws IOException, InterruptedException { WatchService watch ...
- 【Maven jar】打包单个或多个文件,有依赖jar包的将架包一起打包成一个jar包供别的项目引用
之前有一片文章,是打包单个java文件的.这次想要将http://www.cnblogs.com/sxdcgaq8080/p/8398780.html 打包成jar包,发现这个java文件中引用了多 ...
- linux下编译qt5.6.0静态库(使用./configure --help来看看都有哪些参数。超详细,有每一个模块的说明。如果改变了安装的目录,需要到安装目录下的bin目录下创建文件qt.conf)(乌合之众)good
linux下编译qt5.6.0静态库 linux下编译qt5.6.0静态库 configure生成makefile 安装选项 Configure选项 第三方库: 附加选项: QNX/Blackberr ...
- [转帖]linux /proc目录下的文件为何无法用vi编辑保存
linux /proc目录下的文件为何无法用vi编辑保存 https://blog.51cto.com/xlogin/1216914 学习一下 之前看过书 这一点 没太仔细看.. xlogin关注8人 ...
- VS Build目录下各文件的作用
VS2010中各种类型文件的作用: .sln 相当于VC6中 .dsw .vcxproj 相当于VC6中 .dsp .suo 相当于VC6中 .ncb .vcxproj.filter ...
- Eclipse下无法自动编译,或者WEB-INF/classes目录下没文件,编译失败的解决办法(转载)
文章来源:http://www.cnblogs.com/xfiver/archive/2010/07/07/1772764.html 1. IOException parsing XML docum ...
随机推荐
- PP: Reconstructing time series into a complex network to assess the evolution dynamics of the correlations among energy prices
Purpose detect the dynamics in time series of their correlation Methodology 1. calculate correlation ...
- linux网卡
手动启动 ifup eth0 查询网卡配置信息 vim /etc/udev/rules.d/70-persistent-net.rules 备注:可以修改网卡名称和MAC地址
- word doc转pdf
from win32com.client import constants, gencache # TODO pip install pywin32 -i http://mirrors.aliyun. ...
- 自动构建自己的ASP.NET Core基础镜像
在开发过程中,我们可以根据自身情况来定制自己的基础镜像,以便加快CI\CD构建速度以及提高开发体验.这里我们就以ASP.NET Core的基础镜像为例来进行讲解. 本次教程代码见开源库:https:/ ...
- css 页面滚动 多背景固定不动
经常看到一些网站,滚动页面但是背景图不会跟着滚动,好像一直固定在浏览器窗口,感觉挺酷的,哇哦 ~ ~ 原来都是 background-attachment 这位大兄弟的功劳 background-at ...
- OPC通信原理在数采中的应用
OPC通信原理在数采中的应用 OPC是Object Linking and Embedding(OLE)for Process Control的缩写,它是微软公司的对象链接和嵌入技术在过程控制方面的应 ...
- JS中使用lambda筛选list
LevelEnum.filter(x=>x.Category=="水利工程")
- Books Exchange (hard version)
The only difference between easy and hard versions is constraints. There are nn kids, each of them i ...
- centos 7 源码安装gogs
gogs 是轻量级的私有git 平台,允许个人通过低配置的服务器安装私有git gogs 的官网地址是:https://gogs.io/ 安装步骤 1)源码安装mysql 2) 源码安装git 3) ...
- command failed: npm install --loglevel error --registry=https://registry.npm 用vue-cli 4.0 新建项目总是报错
昨天新买的本本,今天布环境,一安装vue-cli发现都4.0+的版本了,没管太多,就开始新建个项目感受哈,一切运行顺利,输入 "vue create app" 的时候,一切貌似进展 ...