-1

So I've got the following CMakeLists.txt file to try and build my main.cpp file.

     project(shell)

     set(extra_flags = -std=c++11 -Werror -Wall -Wextra)
     set(CMAKE_CXX_FLAGS $(CMAKE_CXX_FLAGS) $(extra_flags))
     add_executable(shell main.cpp)

At this point, I am just trying to build it with a Hello World program just to make sure everything works. But the flags are there for the rest of the program that I need to write. The actual process of calling cmake . works just fine, but when I use make I get the following error:

[100%] Building CXX object CMakeFiles/shell.dir/main.cpp.o
c++: fatal error: no input files
compilation terminated.
/bin/sh: 1: -o: not found 
CMakeFiles/shell.dir/build.make:54: recipe for target 'CMakeFiles/shell.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/shell.dir/main.cpp.o] Error 127
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/shell.dir/all' failed
make[1]: *** [CMakeFiles/shell.dir/all] Error 2
Makefile:72: recipe for target 'all' failed
make: *** [all] Error 2

I'm new to Ubuntu and the command line, so any help would be greatly appreciated.

Andrew B
  • 9
  • 1
  • 1
  • 2
  • 2
    You do not want an = in your set command. change `set(extra_flags = -std=c++11 -Werror -Wall -Wextra)` to `set(extra_flags -std=c++11 -Werror -Wall -Wextra)` – drescherjm Jan 31 '15 at 02:48
  • 1
    Also change `set(CMAKE_CXX_FLAGS $(CMAKE_CXX_FLAGS) $(extra_flags))` to `set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${extra_flags})` – drescherjm Jan 31 '15 at 02:51
  • Thanks for your response, I have tried both of those changed and I'm still seeing the same error, but this time with extra lines `/bin/sh: 1: -Werror: not found` `/bin/sh: 1: -Wall: not found` `/bin/sh: 1: -Wextra: not found`. My CMakeLists.txt and main.cpp are in the same directory as well if that helps. – Andrew B Jan 31 '15 at 02:55
  • Try deleting CMakeCache.txt and reconfigure with cmake and rebuild. – drescherjm Jan 31 '15 at 03:03
  • Perhaps this will help: http://stackoverflow.com/a/21561742/487892 – drescherjm Jan 31 '15 at 03:06
  • I think that did it. I now have a file in my directory called "shell" with no extension, but it says that it's an executable file. How could I run that file? – Andrew B Jan 31 '15 at 03:21

1 Answers1

1
  • Make sure you use curly brackets ${} (comment above)
  • Make sure you delete your CMakeCache.txt if you want a "reset" (comment above)
  • I also developed the habit to always use set(CMAKE_CXX_FLGAS "${CMAKE_CXX_FLAGS} ${extra_flags}") instead of set(CMAKE_CXX_FLGAS ${CMAKE_CXX_FLAGS} ${extra_flags}) which proved to cause less headache in any of my applications. Try that as well.
  • Use make VERBOSE=1 to see which commands CMake actually runs. You then can mess with the command directly and see how you get it to work.
  • If it's just HelloWorld!, try leaving out the -std=c++11 flag (or any flags, really) and see.
Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
daniel.wirtz
  • 980
  • 7
  • 11