libmemcached在编译的时候,遇到错误:
./config.h:632:15: error: two or more data types in declaration specifiers
#define off_t long int
^
./config.h:632:20: error: two or more data types in declaration specifiers
#define off_t long int
^
./config.h:658:17: error: two or more data types in declaration specifiers
#define ssize_t int
由于config.h
是通过automake
工具生成出来的,所以一时间不知道从什么地方找问题。
先写一个try.c
文件:
#define off_t long int
#define ssize_it int
int main() {
return 1;
}
可以通过编译。
多次尝试发现,和#define的顺序有关,如果#define off_t long int在#define <stdxx.h>之前,则会报错,否则不报错。
通过g++ -E -P try.c > xx
,可以看到:
#define long int __off_t
#define __off_t off_t
如果#define off_t long int
在stdxx.h
之前,则会用long int
代替off_t
变成:
#define long int __off_t
#define __off_t long int
出现循环,因此会报错
而如果#define off_t long int
在stdxx.h
后面
则会因为已经有了#typedef __off_t off_t
而不会执行
此外,在调试过程中发现#include “a.h"也可以用#include <a.h>,以前以为本地的.h文件只能够用”"引入,而不能用<>,现在发现用gcc -I.
,通过-I跟include的目录可以用<>引入本地h文件。
此外,还有g++在-E -P x.c可以得到预处理的输出,也就是一个.cc文件,里面的extern "C" {...}
要求预编译的输出它必须是g++编译。
参考:
https://stackoverflow.com/questions/68845293/error-multiple-types-in-one-declaration-in-header-define-declaration/68859422#68859422
https://stackoverflow.com/questions/1041866/what-is-the-effect-of-extern-c-in-c
https://stackoverflow.com/questions/9073667/where-to-find-the-complete-definition-of-off-t-type