4

I've got another problem with my project. I managed to get cmake to compile it, but make won't run through. I get the error message, that some headers are not found, so I checked my include_directories according to this questions answer: Listing include_directories in CMake

My include_directories has all specified folders listed as I want, but the makefile neither does include an "INC" tag nor does cmake-gui display the include_directories property. Has anyone encountered a similar or likewise problem an can help me?

Edit:

top level cmake:

PROJECT(MyProject) 
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0)
# set the compiler flags
SET(CMAKE_CXX_COMPILER g++)
SET(CMAKE_CXX_FLAGS "-fPIC -g -D DEBUG -Wall -Wfatal-errors -fstrict-aliasing")

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR}
                    ${GLEW_INCLUDE_DIR}
                    ${GLUT_INCLUDE_DIR}
                    ${GSL_INCLUDE_DIRS}                 
                    ${OpenCV_INCLUDE_DIRS} 
                    ${QT_INCLUDE_DIR}           
                    ${MyProject_SOURCE_DIR}/include)

and after that i've got some add_subdirectories. CMake runs without error, but make seems to ignore the last include_directories line.

Community
  • 1
  • 1
sqred
  • 51
  • 1
  • 1
  • 4
  • 1
    what is a "INC" tag? – m.s. May 19 '15 at 13:11
  • I googled how the include directories are specified in a makefile - I assumed that this should be propagated from cmake to the makefile (since it should know where to look for header and sources) – sqred May 19 '15 at 13:13
  • Can you provide a CMakeLists.txt? Maybe it is something simple like include_directories() must be called before add_library and add_executable. – Finn May 19 '15 at 15:21
  • A sample CMakeLists.txt file would be extremely helpful. You also might be seeing that some headers that are in your include path are referencing headers that aren't in your include path. – jluzwick May 19 '15 at 20:16
  • 1
    added a sample. I really hope this is some noob problem – sqred May 21 '15 at 11:16
  • With C++, boost, qt everything may go wrong :D unlikely to be a noob problem, there are dozen of details everyone could miss when dealing with complex dependencies and build systems. – CoffeDeveloper May 21 '15 at 14:05
  • I now switched to qmake and gonna try to make it work this way. Until now there were solveable problems...let's see. – sqred May 22 '15 at 08:29

1 Answers1

2

Here's a quick checklist:

  • Make sure directory paths have no whitespaces, it may not affect CMake directly but it could cause problems to other tools (GCC, mingw-make/make)
  • Make sure you have correct Make command (try to run make in the directory in which you call cmake). Otherwise you can simply add a path to Make in environment so you are sure cmake see it.
  • print directory paths to be sure they are correct and inspect to see if they have whitespaces

    MESSAGE("${Boost_INCLUDE_DIR}")

    MESSAGE("${GLEW_INCLUDE_DIR}")

    ...

  • You actually should add headers to executable (not needed, but if you generate IDE project files you will see headers there to)

  • For each external library used try to compile a simple hello world to detect if that library is correctly installed (make a simple project using simple functions to see if that compiles, links and runs)
  • Make sure include directories path are correct #include <something.h> or #include "something.h" or #include <path/something.h> (or change include path that CMake set up in a wrong way)
  • Do you have installed those external libraries, haven't you? (CMake is not able to find them if you just "unzipped" them somewhere)

The way CMake packages are thought is the only thing I hate about CMake. (I manually setup 1 CMake project for every external library and then link it manually from my projects instead of using "Global Variables"). Most times it relies on some kind of installation process of those libraries, but it could be altered or go wrong in many ways you can't predict, while if you download a specific revision of a external library, build it yourself and set a path manually you are sure that if something is going wrong is fault of library maintainers and not yours or of some missing install information (if that goes wrong that means you are no longer on a working operating system :D )

Melebius
  • 6,183
  • 4
  • 39
  • 52
CoffeDeveloper
  • 7,961
  • 3
  • 35
  • 69
  • 1
    First of all, thanks for your input. I have checked my include directories with cmake-gui and message() gives me the correct paths. make says that an include from ${MyProject_SOURCE_DIR}/include was not found, although its in the include directories. – sqred May 22 '15 at 07:34
  • At this point you have to reproduce the problem to allow further investigation – CoffeDeveloper May 22 '15 at 14:56
  • try: `set (CMAKE_INCLUDE_CURRENT_DIR ON)` – Melroy van den Berg Nov 23 '20 at 22:40
  • Imho that's poor advice re using cmake targets. Sure it's work to get the package configuration correct, but it pays off when using many packages across platforms with different versions to maintain, tests to run and with many external build variables and ways to influence the binaries. if you need target info you can just dump the properties of the target to see what was cached. – StarShine Aug 25 '23 at 07:28