我有以下文件夹结构:
demo_main
|
|---- demo_use
| |
| --- demo_use_main.c
---- demo_1.0
|
--- demo_sample
|
---zmq_sample
|
--- HelloWorld.h
--- HelloWorld.cpp
在文件 demo_main\demo_use\demo_use_main.c 中,我需要调用位于另一个文件夹中的 HelloWorld.cpp 中定义的函数。
demo_use_main.c
#include "HelloWorld.h"
...
int main(int argc, char *argv[])
{
...
HelloWorldPrint();
return 0;
}
HelloWorld.h
void HelloWorldPrint(void);
HelloWorld.cpp
#include<iostream>
#include "HelloWorld.h"
void HelloWorldPrint()
{
std::cout << "function Hello World!" << std::endl;
}
但是在编译时出现错误:
demo_use_main.c:4:10: fatal error: HelloWorld.h: No such file or directory
我的 Cmakelists.txt 看起来像:
demo_main\CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
add_subdirectory(demo_use)
add_subdirectory(demo_1.0)
demo_main\demo_use\CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
include_directories(${CMAKE_CURRENT_LIST_DIR}/../demo_1.0/demo_sample/zmq_sample/)
add_sources(
${CMAKE_CURRENT_LIST_DIR}/demo_use_main.c
...
)
demo_main\demo_1.0\CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
add_subdirectory(demo_sample)
demo_main\demo_1.0\demo_sample\CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
add_subdirectory(zmq_sample)
demo_main\demo_1.0\demo_sample\zmq_sample\CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
project (zmq_demo)
add_sources(${CMAKE_CURRENT_LIST_DIR}/HelloWorld.cpp)
add_executable(${PROJECT_NAME} HelloWorld.cpp)
demo_use_main.c 找不到头文件是缺少什么?如何纠正它?