错误:头定义声明中的一个声明中有多个类型



Github为了编译一个项目(萌芽),我必须首先编译libmemcached。在编译过程中,它会生成一个config.h文件,我认为它来自config.ac。然而,这个config.h导致了问题:

make  all-am
make[1]: Entering directory `/home/tiina/clearwater/sprout/modules/libmemcached'
CXX      libhashkit/libhashkit_libhashkit_la-aes.lo
In file included from ./libhashkit/common.h:40:0,
from libhashkit/aes.cc:38:
./config.h:632:20: error: multiple types in one declaration
#define off_t long int
^
./config.h:632:20: error: declaration does not declare anything [-fpermissive]
./config.h:658:17: error: multiple types in one declaration
#define ssize_t int
^
./config.h:658:17: error: declaration does not declare anything [-fpermissive]
./config.h:635:15: error: multiple types in one declaration
#define pid_t int
^
./config.h:635:15: error: declaration does not declare anything [-fpermissive]
make[1]: *** [libhashkit/libhashkit_libhashkit_la-aes.lo] Error 1
make[1]: Leaving directory `/home/tiina/clearwater/sprout/modules/libmemcached'

这是配置h:

628 /* Define to rpl_malloc if the replacement function should be used. */
629 #define malloc rpl_malloc
630
631 /* Define to `long int' if <sys/types.h> does not define. */
632 #define off_t long int
633
634 /* Define to `int' if <sys/types.h> does not define. */
635 #define pid_t int
636
637 /* Define to rpl_realloc if the replacement function should be used. */
638 #define realloc rpl_realloc
657 /* Define to `int' if <sys/types.h> does not define. */
658 #define ssize_t int

它在Ubuntu中没有遇到这个问题:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)

它在CentOS:中存在此问题

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)

更新:作为@n。1.8e9-我的共享m在哪里。我建议,我挖得更深。

#include <stdio.h>
#define off_t long int
int main() {
int a = 1;
int b = a++;
return 10;
}

以上代码编译,g++ -E -P结果为OK1然后我交换includedefine声明:

#define off_t long int
#include <stdio.h>

以上代码未编译,g++ -E -P导致ERROR然后我删除了define贴花,它再次编译,结果为OK2。

diff OK1 ERROR

输出:

173c173
< typedef __off_t off_t;
---
> typedef __off_t long int;
diff OK1 OK2

输出为空(OK1和OK2相同)。然后我发布了VIM将off_t标记为与longint相同的颜色。也许off_t是一个保留关键字?然后我用offt:更改了off_t

#define offt long int
#include <stdio.h>

它再次编译。

生成config.h的配置脚本出现故障。

631 /* Define to `long int' if <sys/types.h> does not define. */
632 #define off_t long int

如果off_t没有在您的系统中的任何位置定义,这将是很好的。但它是由系统头定义和使用的,很可能是这样的:

typedef long int __off_t;
typedef __off_t off_t;

#define造成了这些定义,使它们在语法上无效。

解决此问题的最简单方法是手动从config.h中删除有问题的#define,并确保包含sys/types.h

最新更新