1

I am trying to include a .h file that is contained inside a directory in its parent. Looks like this:

.
├── fan_controller
├── ip_camera
├── motors
├── pose_and_distance
└── serial_communication

Edit: They are different "subprojects" each of them containing a independent CMakeList, I am workning in the subproject Fan_controller, with its main and its CmakeList inside it, and I want to use files in the motors directory.

They have different files, I am working in fan_controller's main and I am trying to include a file that is inside motors by doing this:

#include "../motors/src/resources/classes/Arduino.h"

If I put the global path it works fine:

#include "/home/kailegh/catkin_ws/src/project/motors/src/resources/classes/Arduino.h"

the thing is that the file is there, I have check it several times and QT autocompletes the path, so it founds it. However when I try to compile, it says:

no such file or directory

I don't know why this happens, should I add something to the CmakeList? The thing is the file is there!! Thanks a lot in advance!

Kailegh
  • 199
  • 1
  • 13

1 Answers1

2

Assuming you have CMakeLists.txt in the root folder (the folder with fan_controller, ip_camera) add the following include_directory statements:

cmake_minimum_required(VERSION 2.8.12)
...
include_directory(fan_controller/src/resources/classes)
# if required: include_directory(ip_camera/src/resources/classes)
if required: include_directory(motors/src/resources/classes)

set(SOURCES fan_controller/src/resources/classes
    fan_controller/src/resources/classes/myfancontroller.cpp
)

add_executable(myfan_controller)

Assuming you have independent projects, you can either use:

PS: QtCreator uses the CMakeLists.txt results and looks into the filesystem.

Community
  • 1
  • 1
Th. Thielemann
  • 2,592
  • 1
  • 23
  • 38
  • sorry, I ll edit my question, each of them is a different subproject, each of them containing independent CMakeLists there is no root CMakeList – Kailegh May 03 '17 at 12:52
  • ummm thanks a lot, I thought I could add them just using the ".."; it seems that only works in header files, when I have tried to use a relative path to a parent un a .cpp it does not work. Thanks a lot, I will try installing them PS should I accept your answer? maybe someone comes up with something to make it work without installing – Kailegh May 05 '17 at 09:53
  • The solution without install is the ExternalProject macro. – Th. Thielemann May 07 '17 at 16:54