1

EDIT 1: verbose make output now included in error, see below as well

I'm currently trying to compile a C++ project with CMake from a different laptop than the one I had been working on before. When I run make after the CMake configuration is done (withouth errors) I get the following error:

$ make
/usr/bin/cmake -S/home/luc/coding/hiwi/peltier-control-panel -B/home/luc/coding/hiwi/peltier-control-panel/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/luc/coding/hiwi/peltier-control-panel/build/CMakeFiles /home/luc/coding/hiwi/peltier-control-panel/build//CMakeFiles/progress.marks
make  -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/luc/coding/hiwi/peltier-control-panel/build'
make  -f CMakeFiles/sio_client.dir/build.make CMakeFiles/sio_client.dir/depend
make[2]: Entering directory '/home/luc/coding/hiwi/peltier-control-panel/build'
cd /home/luc/coding/hiwi/peltier-control-panel/build && /usr/bin/cmake -E 
cmake_depends "Unix Makefiles" /home/luc/coding/hiwi/peltier-control-panel 
/home/luc/coding/hiwi/peltier-control-panel /home/luc/coding/hiwi/peltier-control-
panel/build /home/luc/coding/hiwi/peltier-control-panel/build /home/luc/coding/hiwi/peltier-control-
panel/build/CMakeFiles/sio_client.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/luc/coding/hiwi/peltier-control-panel/build'
make  -f CMakeFiles/sio_client.dir/build.make CMakeFiles/sio_client.dir/build
make[2]: Entering directory '/home/luc/coding/hiwi/peltier-control-panel/build'
[  6%] Building CXX object CMakeFiles/sio_client.dir/lib/socket.io-client-cpp/src/sio_client.cpp.o
/usr/bin/c++ -DSIMULATION -I/home/luc/coding/hiwi/peltier-control-panel/include
 -I/home/luc/coding/hiwi/peltier-control-panel/src 
 -I/home/luc/coding/hiwi/peltier-control-panel/lib
 -I/home/luc/coding/hiwi/peltier-control-panel/lib/websocketpp
 -I/home/luc/coding/hiwi/peltier-control-panel/lib/rapidjson/include
 -I/home/luc/coding/hiwi/peltier-control-panel/lib/WiringPi/wiringPi
 -Wall -Wextra -o3 -std=gnu++11 -MD -MT 
CMakeFiles/sio_client.dir/lib/socket.io-client-cpp/src/sio_client.cpp.o 
-MF CMakeFiles/sio_client.dir/lib/socket.io-client-cpp/src/sio_client.cpp.o.d 
-o CMakeFiles/sio_client.dir/lib/socket.io-client-cpp/src/sio_client.cpp.o 
-c /home/luc/coding/hiwi/peltier-control-panel/lib/socket.io-client-cpp/src/sio_client.cpp
cc1plus: error: too many filenames given; type ‘cc1plus --help’ for usage
cc1plus: fatal error: CMakeFiles/sio_client.dir/lib/socket.io-client-cpp/src/sio_client.cpp.d: No such file or directory
compilation terminated.
make[2]: *** [CMakeFiles/sio_client.dir/build.make:79: CMakeFiles/sio_client.dir/lib/socket.io-client-cpp/src/sio_client.cpp.o] Error 1
make[2]: Leaving directory '/home/luc/coding/hiwi/peltier-control-panel/build'
make[1]: *** [CMakeFiles/Makefile2:175: CMakeFiles/sio_client.dir/all] Error 2
make[1]: Leaving directory '/home/luc/coding/hiwi/peltier-control-panel/build'
make: *** [Makefile:94: all] Error 2

On the old laptop the code compiles without a problem (Ubuntu 16), so it must be independent of the code. On this laptop I have Arch installed, which means I have much newer versions of all of the installed compilers and programs. Boost libraries are requried in my project but it seems to fail even before it gets to the point where it starts compiling and linking that so I don't think it's really relevant. I'm including it only for the sake of completeness.

  • Ubuntu 16:
    • CMake: 3.15.4
    • Make: 4.1
    • g++/gcc: 5.4.0
    • libboost 1.68.0
  • Arch:
    • CMake: 3.21.2
    • Make: 4.2
    • g++/gcc: 11.1.0
    • libboost 1.76.0

I'm not sure this is the reason however, since the only issue I found on the internet that is similar to this has to do with the mingw installation path on Windows, which is certainly not the issue I seem to be facing.

CMake output:

cmake .. -DSIMULATION=TRUE
-- The C compiler identification is GNU 11.1.0
-- The CXX compiler identification is GNU 11.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Using simulated temperature data...
-- Found Boost: /usr/lib64/cmake/Boost-1.76.0/BoostConfig.cmake (found version "1.76.0") found components: system 
-- Linking against boost shared libraries
-- location of boost libraries
-- Boost::system
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE  
-- Linking SIMULATION
-- Configuring done
-- Generating done
-- Build files have been written to: /home/luc/coding/hiwi/peltier-control-panel/build

An interesting fact I have observed is that on the Arch laptop the checks for working C/CXX compilers are skipped whereas they aren't for the Ubuntu laptop. However, I am able to compile programs with gcc/g++ so they must in principle be working.

I've never encountered this problem before, and it's not something that a quick search seems to be able to resolve. I'm hoping someone may have had some experience with this at some point and could point me in the right direction. Any help at all would be greatly appreciated, however.

EDIT

@Stephen Newell thank you very much for your comment, I wasn't aware of this trick! (I'm still somewhat new to using make/cmake.)

Okay so I think I've narrowed it down to this: when running the same CMakeLists.txt on both systems they produce varying compilation commands:

Ubuntu 16:

/usr/bin/c++ -DSIMULATION 
-I/home/luc/coding/hiwi/peltier-heater/include 
-I/home/luc/coding/hiwi/peltier-heater/src 
-I/home/luc/coding/hiwi/peltier-heater/lib -I/home/luc/coding/hiwi/peltier-heater/lib/websocketpp 
-I/home/luc/coding/hiwi/peltier-heater/lib/rapidjson/include 
-Wall -Wextra -o3 -std=gnu++11  
-o CMakeFiles/PIDController.dir/src/PIDController.cpp.o 
-c /home/luc/coding/hiwi/peltier-heater/src/PIDController.cpp

Arch:

/usr/bin/c++ -DSIMULATION 
-I/home/luc/coding/hiwi/peltier-heater/include 
-I/home/luc/coding/hiwi/peltier-heater/src 
-I/home/luc/coding/hiwi/peltier-heater/lib 
-I/home/luc/coding/hiwi/peltier-heater/lib/websocketpp 
-I/home/luc/coding/hiwi/peltier-heater/lib/rapidjson/include 
-Wall -Wextra -o3 -std=gnu++11 
-MT CMakeFiles/PIDController.dir/src/PIDController.cpp.o 
-MF CMakeFiles/PIDController.dir/src/PIDController.cpp.o.d 
-o CMakeFiles/PIDController.dir/src/PIDController.cpp.o 
-c /home/luc/coding/hiwi/peltier-heater/src/PIDController.cpp 

Notice the -MF and -MT flags. If I pass the Ubuntu command in the build folder on my Arch system it compiles without error (though obviously it only does that specific step)

Is there any reason in particular why these flags are being generated on one system but not on the other? Can (and should) I turn them off? Or should I maybe change some configuration in my CMakeLists.txt to correct for this?

ljbkusters
  • 165
  • 7
  • 2
    Can you provide the exact build command that's failing? Building in verbose mode should show it. – Stephen Newell Aug 29 '21 at 00:00
  • What does your CMakeLists.txt look like? Where are your dependencies installed on Arch? You mentioned the MinGW answer being unrelated, but if you are referring to [this answer](https://stackoverflow.com/a/61314971/1678770) -- it may still be relevant. My first thought from the error was that you either are passing a quoted string that contains a space, or you have a path that contains a space -- either of which would be interpreted as multiple files. If you have a dependency in a directory with a space, that would certainly cause this. – Human-Compiler Aug 29 '21 at 00:59
  • Does running the `/usr/bin/c++ ... -MT ....` line manually from command line causes the same error `cc1plus: fatal error:...`? Please share the sources to the program, if possible (i.e. create an [MCVE]). Please _remove the build dir_(!), start fresh, please try `cmake -S. -B_builddir` and then run `cmake --build _builddir --verbose` instead, without `make`. Please try compiling a fresh sample new C++ project. Please try CMake building https://github.com/ttroy50/cmake-examples/tree/master/01-basic/A-hello-cmake for example. Does it work? – KamilCuk Aug 29 '21 at 10:19
  • 1
    `-o3` Did you edit verbose output and add newlines? Did you modify it? For sure, it's invalid - it's `-O3`, not `-o3`,it's odd to specify output file named `3`. Are you sure it's verbatim the output as is? – KamilCuk Aug 29 '21 at 10:20
  • @KamilCuk Yes running the exact command including the -MD -MT and -MF flags reproduces the error. If I remove them it compiles. I'm afraid I can't share my code as it is for work and I'm not allowed to share the source code. When I run cmake I always make sure to clean the build dir but I'll try the specific commands in your comment and get back to you. – ljbkusters Aug 29 '21 at 10:25
  • 2
    It seems that I set the CMAKE_CXX_FLAGS to "-Wall -Wextra -o3" instead of "-O3"... wow, a typo... Still, it compiled on ubuntu with "-o3". Strange! It now compiles by the way, though there now seems to be an error in one of my dependencies (something to do with Boost), though I think that's unrelated. Thank you so much! If you add it as a solution I can give you an upvote. – ljbkusters Aug 29 '21 at 10:31

0 Answers0