【发布时间】:2018-10-25 23:04:57
【问题描述】:
我正在编写 c++ 代码来在我编写的 arduino 项目上运行测试。为了运行它,我需要它包含几个库的模型(原始库在 c++ 中不起作用)。模型在我的 src 目录中,以及在 main.cpp 中的测试。依赖于模型的文件位于 src 的父目录中,我无法修改它们以引用 src,而不会破坏它们在上传到 arduino 时的运行能力。我也无法将模型或 main.cpp 添加到父目录,因为这会干扰 arduino 代码的操作。
所以,我需要将带有模型的子目录添加到编译父目录中的文件时搜索的目录中。
目录大纲:
parent
forTest.h
forTest.cpp
src
parson.h
parson.c
String.h
String.cpp
main.cpp
CMakeLists.txt
build
在这种情况下,main.cpp 有“#include ../forTest.cpp”,forTest.cpp 有“#include parson.h”和“#include String.h”
我目前在 CMakeLists.txt 中运行以下代码:
cmake_minimum_required (VERSION 2.6)
project(makeTest)
include_directories(../ )
set (makeTest_VERSION_MAJOR 1)
set (makeTest_VERSION_MINOR 0)
add_executable(makeTest main.cpp ../forTest.cpp String.cpp parson.c)
然后我使用
从命令行在 build 目录中构建它cmake -G "Unix Makefiles" ../src
make
cmake命令解析成功,但是make命令在构建forTest.cpp时遇到“fatal error: parson.h not found”
我该如何解决这个问题?
编辑:如果这有一个明显的答案,我很抱歉,我对 Cmake 很陌生
编辑第二个:使用 Gergely Nyiri 建议的更改并将 #include 更改为 #include "/usr/include/string.h" 解决了几个错误,但在迈出一步。
在string.h mockup文件中引用如下代码:
#ifndef STRING_H
#define STRING_H
#include "/usr/include/string.h"
using namespace std;
class String {
private:
std::string thisString;
char chars[];
...
#endif
返回错误:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:61:
/Users/douglas/Desktop/parts/makeHolder/testMake/src/string.h:9:14: error:
implicit instantiation of undefined template 'std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >'
std::string thisString;
接下来是:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iosfwd:193:32: note:
template is declared here
class _LIBCPP_TEMPLATE_VIS basic_string;
【问题讨论】: