当我尝试c++
使用编译任何程序时g++
,出现以下错误,堆栈跟踪非常长,这只是一个示例:
...........
/usr/include/x86_64-linux-gnu/bits/byteswap.h:47:2: error: stray ‘\330’ in program
/usr/include/x86_64-linux-gnu/bits/byteswap.h:47:2: error: stray ‘\330’ in program
/usr/include/x86_64-linux-gnu/bits/byteswap.h:47:2: error: stray ‘\340’ in program
/usr/include/x86_64-linux-gnu/bits/byteswap.h:47:2: error: stray ‘\5’ in program
/usr/include/x86_64-linux-gnu/bits/byteswap.h:47:2: error: stray ‘\260’ in program
In file included from /usr/include/endian.h:60:0,
from /usr/include/ctype.h:39,
from /usr/include/c++/4.8/cctype:42,
from /usr/include/c++/4.8/bits/localefwd.h:42,
from /usr/include/c++/4.8/ios:41,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from post_test_5.cpp:1:
/usr/include/x86_64-linux-gnu/bits/byteswap.h:1:1: error: expected unqualified-id before numeric constant
/usr/include/x86_64-linux-gnu/bits/byteswap.h:11:2: error: expected unqualified-id before numeric constant
In file included from /usr/include/endian.h:60:0,
from /usr/include/ctype.h:39,
from /usr/include/c++/4.8/cctype:42,
from /usr/include/c++/4.8/bits/localefwd.h:42,
from /usr/include/c++/4.8/ios:41,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from post_test_5.cpp:1:
/usr/include/x86_64-linux-gnu/bits/byteswap.h:26:31: error: expected declaration before ‘}’ token
示例代码如下post_test_5.cpp
:
#include<iostream>
int main() {
std::cout << "Hello World" << std::endl;
return 0;
}
我尝试按如下方式运行它:
g++ -c post_test_5.cpp
我的gcc
版本和ubuntu版本是:
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
kirill@kirill-ThinkPad-X140e:~/CPlusPlusStuff/PostTest$ lsb_release -d
Description: Ubuntu 14.04 LTS
但是,当我使用gcc
命令编译.c
文件时,一切都正常工作。
这可能是什么原因造成的?
答案1
看起来(至少)文件/usr/include/x86_64-linux-gnu/bits/byteswap.h
不知何故被损坏了。用文本编辑器打开它并检查它是否看起来像一个正常的 C++ 头文件。
如果是这种情况,请使用以下命令重新安装 libc6-dev 包sudo apt-get --reinstall install libc6-dev
如果不是这种情况,您将需要在此处发布文件 post_test_5.cpp 的完整内容以及编译的完整输出。