C++ 文件无法识别:文件截断 GCC 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5713894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 18:43:06  来源:igfitidea点击:

File not recognized: File truncated GCC error

c++eclipsegcc

提问by Adrian

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

我正在尝试使用 Eclipse 在 Linux 中编译一个简单的“Hello World”程序,但我总是得到这个:

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?

有谁知道问题是什么?

回答by Kostyantyn Ivanov

Just remove the object file.

只需删除目标文件。

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

此错误最有可能出现在先前的构建中断并且未完全生成目标文件之后。

回答by Rainer

Just as an info if someone comes around here.

就像有人来这里的信息一样。

Another problem (with the same error) could be, that you are using ccachefor 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进行更快的编译。在这种情况下,损坏的 *.o 文件也在那里。因此,出于这个原因,您必须使用

ccache -C(note the upper case C!)

ccache -C(注意大写 C!)

Wasted me hours the first time ;-)

第一次浪费了我几个小时;-)

回答by Vivek Goel

I think

我认为

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