**
ubantu下简单的使用cmake与make的使用
Step 1:新建一个可执行程序
首先确保你已经安装了cmake 和 g++,如果没有安装,就:
sudo apt-get install cmake g++
然后准备一个工作空间,并准备一些素材:
mkdir learn_cmake_again
cd learn_cmake_again
touch CMakeLists.txt
touch tutoria.cpp
#CMakeLists.txt文件内容
#版本号
cmake_minimum_required (VERSION 2.8)
#项目名
project (Tutorial)
#生成可执行程序 语法:add_executable(可执行程序名 要编译的cpp)
add_executable(Tutorial tutorial.cpp)
//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;
}
现在就可以尝试链接编译成可执行程序了
cmake .
make
./Tutorial 16