File not recognized: File truncated GCC error

C++EclipseGcc

C++ Problem Overview


I'm trying to compile a simple "Hello World" program in Linux using Eclipse, but I always get this:

Building target: hello
Invoking: GCC C++ Linker
g++  -o "hello"  ./src/hello.o   
./src/hello.o: file not recognized: File truncated
collect2: ld returned 1 exit status
make: *** [hello] Error 1

**** Build Finished ****

Does anyone have an idea what the problem is?

C++ Solutions


Solution 1 - C++

Just remove the object file.

This error most likely appeared after the previous build was interrupted and object file was not generated completely.

Solution 2 - C++

Just as an info if someone comes around here.

Another problem (with the same error) could be, that you are using ccache for faster compilation. In this case, the corrupt *.o file is there as well. So for that reason you have to clean the cache with

ccache -C (note the upper case C!)

Wasted me hours the first time ;-)

Solution 3 - C++

I think

g++  -o "hello"  ./src/hello.o  
should be ./src/hello.(c | cpp | cc depending on your language type)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAdrianView Question on Stackoverflow
Solution 1 - C++Kostyantyn IvanovView Answer on Stackoverflow
Solution 2 - C++RainerView Answer on Stackoverflow
Solution 3 - C++Vivek GoelView Answer on Stackoverflow