C ++使前向声明失败-在docker中运行

用户名

我正在使用docker编译以下库:

https://github.com/hot-stuff/libhotstuff

使用以下脚本:

FROM alpine:latest
RUN apk update
RUN apk add --no-cache git gcc g++ make cmake libuv-dev openssl-dev gmp-dev libsodium-dev autoconf
RUN git clone https://github.com/hot-stuff/libhotstuff.git && cd libhotstuff/ && git submodule update --init --recursive
RUN cd libhotstuff && cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED=ON -DHOTSTUFF_PROTO_LOG=ON && make

导致以下异常:

In file included from /libhotstuff/include/hotstuff/util.h:21,
                 from /libhotstuff/src/util.cpp:17:
/libhotstuff/salticidae/include/salticidae/util.h:244:20: error: field 't0' has incomplete type 'salticidae::timeval'
  244 |     struct timeval t0;
      |                    ^~
/libhotstuff/salticidae/include/salticidae/util.h:71:30: note: forward declaration of 'struct salticidae::timeval'
   71 | void sec2tv(double t, struct timeval &tv);
      |                              ^~~~~~~
make[2]: *** [CMakeFiles/hotstuff.dir/build.make:82: CMakeFiles/hotstuff.dir/src/util.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:289: CMakeFiles/hotstuff.dir/all] Error 2
make: *** [Makefile:149: all] Error 2

同时,我能够在自己的计算机和其他计算机上很好地运行它。(手动在docker外部)

卡米尔库克

C ++使前向声明失败-在docker中运行

链接的源文件util.h#include <sys/time.h>被需要的struct timeval实际上,标识符的类型不完整。

从技术上讲,C源包含最好包含在内部extern "C",所以在第28行

#ifdef __cplusplus     // POSIX headers should be inside extern "C"
extern "C" {           // but there are no actual platforms 
#endif                 // where this is needed, so anyway...
#include <getopt.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/time.h>  // add this for timeval
#ifdef __cplusplus
}
#endif

祝你好运,它应该可以工作。

同时,我能够在自己的计算机和其他计算机上很好地运行它。

很可能您可以使用来运行它glibc,而alpine将其musl用作C标准库实现。您可能希望省去修补库的工作,因为可能需要修复其他不兼容问题,并且在向上游修补库以进行使用之前musl,我建议您只使用兼容的docker映像,该映像使用glibc

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章