0

I have the following arrangement in my project:

enter image description here

And, my CMakeLists.txt has the following text:

cmake_minimum_required(VERSION 2.8.9) project(cmake_test) # Bring the headers into the project include_directories("*.hh") # the file(GLOB...) allows for wildcard additions: file(GLOB SOURCES "*.cpp") add_executable(OrganizationExecutable ${SOURCES}) 

It is giving the following error:

"C:\Program Files\JetBrains\CLion 2019.3.3\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\pc\source\repos\Doxygen\input_cpp_files -- Configuring done -- Generating done -- Build files have been written to: C:/Users/pc/source/repos/Doxygen/input_cpp_files/cmake-build-debug Cannot get compiler information: Compiler exited with error code 1: C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe -xc++ -IC:/Users/pc/source/repos/Doxygen/input_cpp_files/*.hh -g -fpch-preprocess -v -dD -E Using built-in specs. COLLECT_GCC=C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe Target: x86_64-w64-mingw32 Configured with: ../../../src/gcc-8.1.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh-rev0, Built by MinGW-W64 project' --with-bugurl=https://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/lib -L/c/mingw810/prerequisites/x86_64-zlib-static/lib -L/c/mingw810/prerequisites/x86_64-w64-mingw32-static/lib ' Thread model: posix gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project) COLLECT_GCC_OPTIONS='-I' 'C:/Users/pc/source/repos/Doxygen/input_cpp_files/*.hh' '-g' '-fpch-preprocess' '-v' '-dD' '-E' '-D' '___CIDR_DEFINITIONS_END' '-shared-libgcc' '-mtune=core2' '-march=nocona' C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/8.1.0/cc1plus.exe -E -quiet -v -I C:/Users/pc/source/repos/Doxygen/input_cpp_files/*.hh -iprefix C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/ -D_REENTRANT -D ___CIDR_DEFINITIONS_END C:\Users\pc\AppData\Local\Temp\compiler-file18127741905635620224 -mtune=core2 -march=nocona -fpch-preprocess -g -fworking-directory -dD ignoring duplicate directory "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++" ignoring duplicate directory "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32" ignoring duplicate directory "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward" ignoring duplicate directory "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/8.1.0/include" ignoring nonexistent directory "C:/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../include" ignoring duplicate directory "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed" ignoring duplicate directory "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include" ignoring nonexistent directory "C:/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/mingw/include" cc1plus.exe: warning: C:/Users/pc/source/repos/Doxygen/input_cpp_files/Employee.hh: not a directory #include "..." search starts here: #include <...> search starts here: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++ C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32 C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include End of search list. cc1plus.exe: error: too many filenames given. Type cc1plus.exe --help for usage [Failed to reload] 

How can I fix it?

1
  • include_directories is for the directory name like /include/ not a list of header files Commented Apr 20, 2021 at 20:30

2 Answers 2

2

include_directories("*.hh")

is invalid. What happens is that *.hh is confusing the compiler. There is no directory named literally *.hh. And as the name suggests *.hh is not a directory, but rather a glob pattern to match headers with .hh extension.

If you want to add current path (ie. the path with current CMakeLists.txt) file into header search paths, do:

include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 

To include files in the same directory as source file, just use "file" instead of <file> in #include statements. And prefer target_include_directories over include_directories.

If you want to add header files into sources of your project, do:

file(GLOB SOURCES "*.cpp" "*.hh") add_executable(OrganizationExecutable ${SOURCES}) 

Note that cmake discourages the usage of file(GLOB to listing source files. You should prefer to enumerate files in your CMakeLists.txt one by one instead.

Sign up to request clarification or add additional context in comments.

1 Comment

target_include_directories is now preferred to include_directories. Just saying ;)
1

As @Cory Kramer Mentioned, You should be including the folder which contains all your header files into cmake, rather than providing the actual files.

If your Header files are in same location as your main file (.cpp) file, then that would not be necessary.

The include_directories are generally used when your include files and your source codes are in diffferent folders ( which generally would be the case on a professionaly maintained code like blas libraries and so on ).

@Edited based on comments by @Devolus

Eg: Lets say if the directory in which your header files are present is "mysourcebase/includepath/directory" then you should do

include_directories(mysourcebase/includepath/directory) 

It is similar to using the "-I" flag while compilation which lets you know what directories to be included while compiling a code.

Eg :

gcc -I/mysourcebase/includepath/directory main.cpp 

3 Comments

You should add an example like include_directories(mysourcebase/includepath/directory)
@Devolus, Thanks for the tip. Updated the answer accordingly..!
You should add a note that GLOBbing is frowned upon; each relevant source file should be specified. Also target_include_directories is preferred over include_directories now. I recommend the book "Professional CMake" by Craig Scott for more information: crascit.com/professional-cmake

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.