g++ output: file not recognized: File format not recognized

I ran into this error in building something - it turned out to be due to a previous build failing while compiling a source file to an .o file - that .o file was incomplete or corrupted, so when I tried another build it gave this error on that file.

The solution was to just delete the .o file (or run make clean, if you have a makefile with that target).


This is wrong:

 g++ -c src/CNumber.cpp src/CNumber.h -o src/CNumber.o

You shouldn't "compile" .h files. Doing so will create precompiled header files, which are not used to create an executable. The above should simply be

 g++ -c src/CNumber.cpp -o src/CNumber.o

Similar for compiling the other .cpp files