Whenever I wanted to include a directory that was located outside of my project with Clion I would use the -I somedir
flag. This time however, what I want to do is to have a hierarchy like this:
/project
CMakeLists.txt
/src
/Graph
Graph.h
Graph.cpp
/Dijkstra
Dijkstra.h
Dijstra.cpp
I want my code in a /src
directory. And not only that, but also, for example, inside the file Dijkstra.h
I want to include the Graph.h like this: #include "Graph/Graph.h
and not like this: #include "../Graph/Graph.h
.
If I only add an -I src
flag, then if I am inside the Dijkstra.h
file and I wanted to include Graph.h
, I would have to write #include "../Graph/Graph.h
, which is not what I want.
So I tried to also add INCLUDE_DIRECTORIES(src)
. That fixed the problem above, however when tried to compiled, I got a linker error undefined reference to...
.
So I tried adding the files one by one like this:
set(SOURCE_FILES
src/Dijkstra/Dijkstra.h
src/Dijkstra/Dijkstra.cpp
src/Graph/Graph.h
src/Graph/Graph.cpp)
add_executable(someprojectname ${SOURCE_FILES})
and that brought back the previous problem, where I had to include the files like this: #include "../Graph/Graph.h"
.
How can I do this properly to get the behavior I want ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…