我试图编译一个小的.cpp文件但遇到问题,因为这个文件利用了许多其他文件中的功能。基本上,我克隆了ZCash repo,目前我正在尝试使用该项目中的特定文件进行一些测试。当我编译整个ZCash repo时,我克隆的一切都很完美,但是当我尝试编译文件时,我和其中一些文件一起工作会出现语法错误。
我的Makefile:
CC = g++
CFLAGS = -std=c++11 -Wall -g -c
IDIR = /home/parallels/zcash/src/
INC = -I /home/parallels/zcash/src/ -I
/home/parallels/zcash/depends/x86_64-unknown-linux-gnu/include/
VPATH = /home/parallels/zcash/src/
all: Main.o KeyGen.o prf.o uint256.o sha256.o
$(CC) Main.o KeyGen.o prf.o uint256.o sha256.o -o keygenerator
Main.o: Main.cpp
$(CC) $(CFLAGS) Main.cpp $(INC)
KeyGen.o: KeyGen.cpp
$(CC) $(CFLAGS) KeyGen.cpp $(INC)
prf.o: prf.cpp
$(CC) $(CFLAGS) prf.cpp $(INC)
uint256.o: uint256.cpp
$(CC) $(CFLAGS) uint256.cpp $(INC)
sha256.o: sha256.cpp
$(CC) $(CFLAGS) sha256.cpp $(INC)
clean:
rm -rf *.o keygenerator
正在编译的.cpp文件引用这些其他文件:
Main.cpp的:
#include "KeyGen.h"
#include "uint252.h"
#include "uint256.h"
#include <string>
KeyGen.cpp
#include "KeyGen.h"
#include "prf.h"
prf.cpp
#include "prf.h"
#include "crypto/sha256.h"
uint256.cpp
#include "uint256.h"
#include "utilstrencodings.h"
#include <stdio.h>
#include <string.h>
sha256.cpp
#include "crypto/sha256.h"
#include "crypto/common.h"
#include <string.h>
#include <stdexcept>
因此,在我尝试编译这些文件后,我收到以下错误:
g ++ -std = c ++ 11 -Wall -g -c Main.cpp -I / home / parallels / zcash / src / -I / home / parallels / zcash / depends / x86_64-unknown-linux-gnu /包括/
g ++ -std = c ++ 11 -Wall -g -c KeyGen.cpp -I / home / parallels / zcash / src / -I / home / parallels / zcash / depends / x86_64-unknown-linux-gnu /包括/
g ++ -std = c ++ 11 -Wall -g -c prf.cpp -I / home / parallels / zcash / src / -I / home / parallels / zcash / depends / x86_64-unknown-linux-gnu /包括/
g ++ -std = c ++ 11 -Wall -g -c uint256.cpp -I / home / parallels / zcash / src / -I / home / parallels / zcash / depends / x86_64-unknown-linux-gnu /包括/
g++ -std=c++11 -Wall -g -c sha256.cpp -I /home/parallels/zcash/src/ -I /home/parallels/zcash/depends/x86_64-unknown-linux-gnu/include/
In file included from /usr/include/x86_64-linux-gnu/bits/byteswap.h:35:0,
from /usr/include/endian.h:60,
from /usr/include/x86_64-linux-gnu/bits/waitstatus.h:64,
from /usr/include/stdlib.h:42,
from /home/parallels/zcash/src/crypto/sha256.h:9,
from sha256.cpp:5:
/home/parallels/zcash/src/compat/endian.h:111:17: error: expected unqualified-id before ‘__extension__’
inline uint16_t htobe16(uint16_t host_16bits)
^
在违规档案/home/parallels/zcash/src/compat/endian.h:111:17中,htobe16使用如下:
#if HAVE_DECL_HTOBE16 == 0
inline uint16_t htobe16(uint16_t host_16bits) //line #111
{
return bswap_16(host_16bits);
}
#endif // HAVE_DECL_HTOBE16
还有一个文件:/usr/include/endian.h,如下引用htobe16。
# include <bits/byteswap.h> //line #60
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define htobe16(x) __bswap_16 (x)
# define htole16(x) (x)
# define be16toh(x) __bswap_16 (x)
# define le16toh(x) (x)
注意: 我正在编译的所有.cpp文件都位于我克隆的ZCash存储库和我创建的新文件夹中(想知道这可能是问题)。
我目前正在处理的文件夹包含: KeyGen.cpp
KeyGen.h
Main.cpp的
生成文件
prf.cpp
prf.h
serialize.h
sha256.cpp
sha256.h
uint252.h
uint256.cpp
uint256.h
对不起,很长的帖子,我真的很感谢你的时间,真的很感激一些帮助!
答案 0 :(得分:0)
多个相同名称的宏已经声明了内联函数。与此问题类似:error: expected unqualified-id before ‘__extension__’ in Linux (Cent OS)
可能与整个项目中要构建的片中未配置的部分有关,因为这个Github讨论似乎表明: https://github.com/bitcoin/bitcoin/issues/5920