【问题标题】:Makefile and errors compiling separate files from a big projectMakefile 和错误从一个大项目编译单独的文件
【发布时间】:2017-12-01 04:57:36
【问题描述】:

我正在尝试编译一个小的 .cpp 文件,但由于该文件利用了许多其他文件中的功能,因此遇到了问题。基本上,我克隆了 ZCash 存储库,目前正在尝试使用该项目中的特定文件进行一些测试。当我编译整个 ZCash 存储库时,我克隆的一切都运行良好,但是当我尝试编译文件时,我正在使用其中一些文件出现语法错误。

我的 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 存储库和我创建的新文件夹中(想知道这是否是问题所在)。

我目前正在处理的文件夹包含: 密钥生成器.cpp

KeyGen.h

Main.cpp

生成文件

prf.cpp

prf.h

序列化.h

sha256.cpp

sha256.h

uint252.h

uint256.cpp

uint256.h

抱歉,这篇文章太长了,非常感谢您抽出宝贵时间并非常感谢您的帮助!

【问题讨论】:

  • 当您将有问题的源文件之一简化为 minimal complete example 时会发生什么?看起来好像endian.h 引用了uint16_t,那么uint16_t 定义在哪里,如果它不在endian.h 中,那么endian.h #include 是否包含其他包含定义的标头?
  • @Beta 我已经修改了问题以在有问题的文件上添加一些代码。请注意,错误消息中的缩进丢失了,“^”应该指向 htobe16 而不是 uint16_t。感谢您的帮助,希望此编辑能够为您提供所需的信息。
  • 我无法从这些片段中重现错误。考虑编写 HelloWorld。

标签: c++ gcc makefile compilation g++


【解决方案1】:

内联函数已由多个同名宏声明。类似这个问题:error: expected unqualified-id before ‘__extension__’ in Linux (Cent OS)

可能与您从整个项目中构建的切片的未配置部分有关,因为这个 Github 讨论似乎表明: https://github.com/bitcoin/bitcoin/issues/5920

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    相关资源
    最近更新 更多