main.c
#include "hello.h"
int main()
{
hello();
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(hello)
set(SRC_LIST main.c)
include_directories("${PROJECT_SOURCE_DIR}/hello")
add_subdirectory(hello)
add_executable(main ${SRC_LIST})
target_link_libraries(main hello)
在main.c同级目录下新建一个文件hello
hello.h
#ifndef __HELLO_H__
#define __HELLO_H__
void hello();
#endif
hello.c
#include <stdio.h>
#include "hello.h"
void hello()
{
printf("hello world\n");
}
CMakeLists.txt
add_library(hello hello.c)