Ac 、 Bc 、 Cc という 3 つのファイルがあり、そのすべてに #include common.h が含まれています。
common.h に「sys/socket.h」をインクルードし、common.h をマクロで保護します。
#ifndef __COMMON_H
#define __COMMON_H
// body of file goes here
#endif
コードをコンパイルすると、以下のようないくつかのエラーが発生します
In file included from /usr/include/sys/socket.h:40,
from tcpperf.h:4,
from wrapunix.c:1:
/usr/include/bits/socket.h:425: error: conflicting types for 'recvmmsg'
/usr/include/bits/socket.h:425: note: previous declaration of 'recvmmsg' was here
In file included from /usr/include/sys/socket.h:40,
from tcpperf.h:4,
from wrapsock.c:1:
wrapunix.c と wrapsock.c を見るとわかるように、どちらにも tcpperf.h が含まれていますが、tcpperf.h はマクロで保護されていますが、gcc は recvmsg が複数回宣言されていると不平を言っています。この問題を解決するにはどうすればよいですか?
更新: これは、問題を引き起こしている tcpperf.h のヘッダーです。
#ifndef _TCPPERF_H
#define _TCPPERF_H
#include <sys/types.h>
#include <sys/socket.h>
#include <time.h>
#include <regex.h>
#include <errno.h>
#include <sched.h>
#include <pthread.h>
#include <argp.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <linux/tcp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <sys/prctl.h>
#include <unistd.h>
#include <sys/wait.h>
#endif
上記のエラーは、次のような「-combine -fwhole-program」フラグを gcc に指定することで再現できます。
gcc -std=gnu99 -Wall -combine -fwhole-program -I. error.c wrapunix.c wrapsock.c file1.c file2.c -o file2 -lrt