cmake实践:包含头文件的hello wrold
1. 建立hello.h
1 #ifndef _ROOV_HELLO_H_ 2 #define _ROOV_HELLO_H_ 3 4 void hello(const char* name); 5 6 #endif //_ROOV_HELLO_H_
2. 修改hello.c
1 #include<stdio.h> 2 #include "hello.h" 3 4 void hello(const char* name) 5 { 6 printf("hello, %s.\n", name); 7 }
3. 新建main.c
1 #include "hello.h" 2 int main() 3 { 4 hello("roov"); 5 return 0; 6 }
4. 修改CMakeLists.txt
1 project(HELLO) 2 set(SRC_LIST main.c hello.c) #在SRC_LIST中新增了main.c 3 add_executable(hello ${SRC_LIST})
5. cmake和make
输出hello, roov.