下面是画一下文件目录
├── CMakeLists.txt
├── include
│ └── hello.h
└── src
├── hello.c
└── main.c
hello.c
1 #include <stdio.h>
2 #include "hello.h"
3 void Helloprint()
4 {
5 printf( "Hello Headers!\n");
6 }
mian.c
1 #include "hello.h"
2
3 int main(int argc, char *argv[])
4 {
5 Helloprint();
6 return 0;
7 }
hello.h
1 #ifndef __HELLO_H__
2 #define __HELLO_H__
3
4 void Helloprint();
5 #endif
CMakeLists.txt
1 # Set the minimum version of CMake that can be used
2 # To find the cmake version run
3 # $ cmake --version
4 cmake_minimum_required(VERSION 2.8.12)
5
6 # Set the project name
7 project (hello_headers)
8
9 # Create a sources variable with a link to all cpp files to compile
10 set(SOURCES
11 src/hello.c
12 src/main.c
13 )
14
15 # Add an executable with the above sources
16 add_executable(hello_headers ${SOURCES})
17
18 # Set the directories that should be included in the build command for this target
19 # when running g++ these will be included as -I/directory/path/
20 target_include_directories(hello_headers
21 PRIVATE
22 ${PROJECT_SOURCE_DIR}/include
23 )