cmake 相比automake 最大的區別是: 步驟沒有automake那麼多ios
main.cppui
#include<iostream> #include"student.h" using namespace std; int main() { Student stu; stu.set(); stu.display(); cout<<"i am soyo"<<endl; return 0; }
student.cppspa
#include<iostream> #include"student.h" using namespace std; void Student::display() { cout<<"num:"<<num<<endl; cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl; } void Student::set() { cin>>num>>name>>sex; }
student.h3d
#include<iostream> #include<string> using namespace std; class Student { public: void set(); void display(); private: int num; string name; char sex; };
cmake過程:code
1.建一個CMakeLists.txt文件:(CMakeLists.txt 文件名字要正確,否則沒法執行cmake .)blog
CMakeLists.txt:ci
# CMake 最低版本號要求 cmake_minimum_required (VERSION 3.5.1) # 項目信息 project (main) # 查找當前目錄下的全部源文件 # 並將名稱保存到 DIR_SRCS 變量 aux_source_directory(. DIR_SRCS) # 指定生成目標 add_executable(main ${DIR_SRCS})
2.cmake .
3. make
4.生成可執行的文件string