在Amazon EC2上的socket.h中的编译器错误

Compiler error in socket.h on Amazon EC2

本文关键字:编译器 错误 socket Amazon EC2 上的      更新时间:2023-10-16

我正试图在我的EC2实例上编译比特币,我遇到了一个我无法解决的问题。构建脚本在以下命令

处停止
g++ -c -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -g   -DMSG_NOSIGNAL=0 -DBOOST_SPIRIT_THREADSAFE -DUSE_UPNP=1 -DUSE_IPV6=1 -I/home/ec2-user/bitcoin/src/leveldb/include -I/home/ec2-user/bitcoin/src/leveldb/helpers -DHAVE_BUILD_INFO -I"/home/ec2-user/bitcoin/src" -I"/home/ec2-user/bitcoin/src/obj" -I"/usr/local/include" -I"/usr/include/openssl" -MMD -MF obj/alert.d -o obj/alert.o alert.cpp

返回以下错误

In file included from /usr/include/sys/socket.h:40:0,
                 from compat.h:19,
                 from netbase.h:11,
                 from util.h:27,
                 from alert.h:13,
                 from alert.cpp:11:
/usr/include/bits/socket.h:231:5: error: expected identifier before numeric constant
/usr/include/bits/socket.h:231:5: error: expected ‘}’ before numeric constant
/usr/include/bits/socket.h:231:5: error: expected unqualified-id before numeric constant
In file included from compat.h:19:0,
                 from netbase.h:11,
                 from util.h:27,
                 from alert.h:13,
                 from alert.cpp:11:
/usr/include/sys/socket.h:254:1: error: expected declaration before ‘}’ token

我试过用-std=c++0x选项集编译,但没有什么区别。这是我唯一能想到的。

我敢打赌,你有一些头文件是#define一个宏干扰socket.h。你是否能够编译一个只包含<sys/socket.h>而不包含其他内容的程序?

下一件要检查的事情是查看/usr/include/bits/socket.h并查看第231行上的内容(第一个错误发生的地方)。如果代码看起来没问题,那么下一步就是看看预处理后的源代码是什么样子的。要获得预处理的输出,在命令行中将-c选项替换为-E,并将-o obj/alert.o选项更改为-o alert.ii,以便将预处理器输出放入文件alert.ii中。

如果您比较alert.ii/usr/include/bits/socket.h的内容,您可以看到它是否按预期编译。特别是,如果有一个宏将某些东西定义为意想不到的东西,你会在编译器指出的位置看到明显错误的代码。