我在Clion遇到了一个烦人的问题,就是我的项目总是有标题错误
这是我的CmakeLists.txt
:
cmake_minimum_required(VERSION 3.6)
project(geometry)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(PROJECT_SOURCE_DIR geo)
set(CMAKE_INCLUDE_CURRENT_DIR geo)
include_directories("${PROJECT_BINARY_DIR}")
include_directories(${CMAKE_BINARY_DIR}/geo/)
set(SOURCE_FILES
geo/Circle.cpp
geo/Circle.h
geo/geo.h
geo/ICircle.cpp
geo/ICircle.h
geo/IPoint.cpp
geo/IPoint.h
geo/IRectangle.cpp
geo/IRectangle.h
geo/IShape.cpp
geo/IShape.h
geo/IText.cpp
geo/IText.h
geo/Point.cpp
geo/Point.h
geo/Rectangle.cpp
geo/Rectangle.h
geo/Shape.cpp
geo/Shape.h
geo/Text.cpp
geo/Text.h
owl/IThing.cpp
owl/IThing.h
owl/owl.h
owl/Thing.cpp
owl/Thing.h
rdfs/IResource.cpp
rdfs/IResource.h
rdfs/rdfs.h
rdfs/Resource.cpp
rdfs/Resource.h
AllInOne.cpp
example.cpp
geometry.owl)
add_executable(geometry ${SOURCE_FILES})
这是example.cpp
,它也是主要的cpp:
#include <autordf/Factory.h>
#include <geo/geo.h>
using namespace geo;
int main(int argc, char ** argv) {
autordf::Factory f;
f.addNamespacePrefix("geo", "http://example.org/geometry#");
autordf::Object::setFactory(&f);
geo::Rectangle r("http://example.org/myfancyrectangle");
// Set one of my rectangle coordinates - the long way
geo::Point tl;
tl.setX(1.0);
tl.setY(2.0);
r.setTopLeft(tl);
// Set one of my rectangle coordinates - the short way
r.setBottomRight(geo::Point().setX(11).setY(12));
// Set result of my work
f.saveToFile(stdout, "turtle");
}
它在终端中完美运行但在Clion中的结果是:
Scanning dependencies of target geometry
[ 5%] Building CXX object CMakeFiles/geometry.dir/geo/Circle.cpp.o
[ 11%] Building CXX object CMakeFiles/geometry.dir/geo/ICircle.cpp.o
[ 17%] Building CXX object CMakeFiles/geometry.dir/geo/IPoint.cpp.o
/home/burning/projects/autordf_projects/geometry/geo/Circle.cpp:2:24: fatal error: geo/Circle.h: No such file or directory
#include <geo/Circle.h>
^
compilation terminated.
/home/burning/projects/autordf_projects/geometry/geo/ICircle.cpp:2:25: fatal error: geo/ICircle.h: No such file or directory
#include <geo/ICircle.h>
^
compilation terminated.
/home/burning/projects/autordf_projects/geometry/geo/IPoint.cpp:2:24: fatal error: geo/IPoint.h: No such file or directory
#include <geo/IPoint.h>
^
compilation terminated.
[ 23%] Building CXX object CMakeFiles/geometry.dir/geo/IRectangle.cpp.o
/home/burning/projects/autordf_projects/geometry/geo/IRectangle.cpp:2:28: fatal error: geo/IRectangle.h: No such file or directory
#include <geo/IRectangle.h>
^
compilation terminated.
make[3]: *** [CMakeFiles/geometry.dir/geo/ICircle.cpp.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[3]: *** [CMakeFiles/geometry.dir/geo/Circle.cpp.o] Error 1
make[3]: *** [CMakeFiles/geometry.dir/geo/IPoint.cpp.o] Error 1
make[3]: *** [CMakeFiles/geometry.dir/geo/IRectangle.cpp.o] Error 1
make[2]: *** [CMakeFiles/geometry.dir/all] Error 2
make[1]: *** [CMakeFiles/geometry.dir/rule] Error 2
make: *** [geometry] Error 2
geo/
中的一个标头文件(例如Circle.cpp
)如下所示:
/** @cond internal */
#include <geo/Circle.h>
// This is auto generated code by AutoRDF, do not edit !
namespace geo {
Circle::Circle(const std::string& iri) : autordf::Object(iri, ICircle::TYPEIRI) {
}
Circle::Circle(const Object& other) : autordf::Object(other) {
}
std::vector<Circle> Circle::find() {
return findHelper<Circle>(ICircle::TYPEIRI);
}
}
/** @endcond internal */
所以,问题是我不能在头文件中包含其他头文件。如您所见,错误将是:
/home/burning/projects/autordf_projects/geometry/geo/Circle.cpp:2:24: fatal error: geo/Circle.h: No such file or directory
#include <geo/Circle.h>
^
compilation terminated.
有人可以帮我吗?
答案 0 :(得分:0)
如评论中所述,您应该使用:
include_directories("${PROJECT_SOURCE_DIR}")
而不是:
include_directories("${PROJECT_BINARY_DIR}")
从PROJECT_SOURCE_DIR
的文档中我们得到了:
当前项目的顶级源目录。
从PROJECT_BINARY_DIR
的文档中我们得到了:
为项目构建目录的完整路径。
因此,除非您允许项目的源代码构建,否则您可能希望将源目录用作包含目录,不构建目录。