1

I have the following problem: I try to start coding C++ for a little project in my company. Therefore I received a precoded program. Since I am new to C++ i thought about using a IDE, CLion in my case. The precoded program was build with vim at the console (I don't know if this is the reason for the following, I guess building/linking, problem)

My folder/file structure looks like this:

src
|_subprogramA
  |_src
    |_main.hpp
    |_main.cpp
    |_ ...
|_subprogramB
    |_ ..
  |_src
    |_...
  ...
|_libhttp
  |_src
    |_http.hpp
    |_http.cpp
    |_ ..
CMakeList.txt

In my CMakeList.txt, the paths to all .cpp and .hpp files are set by set(Source_Files ) add_executables(projectname ${SOURCE_FILES})

When i build subprogramA, i get the errormessage: fatal error: http/http.hpp: No such file or directory. It is included by #include . Why does the compiler not find the http.hpp file in libhttp/src/http although it is specified in CMakeList? Is there a way to tell it where it is located except changing the "include" to the full path: #include libhttp/src/http.hpp or #include ../../lib.. and so on? (I do not wanna change this codepath since it is used by other persons in another company) I wounder that i can run the tool via console but i cant build it with clion IDE. Best regards, I am happy for every help. And sorry if the question is kinda stupid but starting c++ with a kinda big precoded tool without IDE seems to be impossible for me ^^

Frank :)

arved
  • 4,401
  • 4
  • 30
  • 53
MasterF
  • 33
  • 1
  • 5
  • Well, the problem is not related directly with CLion, it is actually with CMake. Look [this directive](https://cmake.org/cmake/help/v3.9/command/include_directories.html). The problem is the compiler does not know where the file http.hpp is. My advice: you could try to evolve slowly the project. You could start with a few files, make sure the compiler see each file, the executable is properly formed (even empty) and then include the rest of files in small steps. – JTejedor Jul 06 '17 at 14:08
  • Thanks, ye thats an option of course. But than i still have the problem that i have to change the include path if the compiler does not see any file. Is there no way to tell the compiler where the files located (import a folder or whatever)? – MasterF Jul 06 '17 at 14:28
  • Could you follow this [answer](https://stackoverflow.com/a/24571137/1967221)? In a nutshell. When you create several projects (two executable and a library), you need to add dependencies. The way to add this dependencies is explained in the posted answer, trough INCLUDE_DIRECTORIES for header location and LINK_DIRECTORIES + TARGET_LINK_LIBRARIES for libraries. As I said before, I would start with the library libhttp, and I make sure, the library compilation would be successful, after that, you can face the executable compilation. – JTejedor Jul 06 '17 at 15:55

0 Answers0