CMAKE简单入门
单目录工程的CMAKE配置与编译
如果所有编译需要的文件都在同一个目录下,此时CMAKE比较容易配置。
首先建立如下所示的文件夹 Test
:
Test
-- main.cpp
-- tools.h
-- tools.cpp
然后在 tools.h
中声明一个函数 void display()
,然后在 tools.cpp
中完成函数定义。最后在 main.cpp
中调用 void display()
函数。
比如,文件 tools.h
如下:
#ifndef _TOOLS_H
#define _TOOLS_H
#endif
#include <iostream>
using namespace std;
void display();
文件 tools.cpp
如下:
#include "tools.h"
void display()
{
cout<<"This CMAKE project works!"<<endl;
}
文件 main.cpp
如下: