Take the 2-minute tour ×

I have three files, say A.c , B.c and C.c, all of which #include common.h

In common.h, I include "sys/socket.h" and I protect the common.h by macros:

#ifndef __COMMON_H
#define __COMMON_H
// body of file goes here

When i compile the code, I get several errors such as below

             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
             from tcpperf.h:4,
             from wrapsock.c:1:

As you can see wrapunix.c and wrapsock.c, they both include tcpperf.h, but tcpperf.h is guarded with macros,yet gcc complains that recvmsg was declared multiple times. How do I resolve this issue?

Update: Here is the header of tcpperf.h, that is causing issues

#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>

The above error can be reproduced by providing "-combine -fwhole-program" flags to gcc such as

gcc -std=gnu99 -Wall -combine -fwhole-program -I. error.c wrapunix.c wrapsock.c file1.c file2.c -o file2 -lrt

share|improve this question
Check for circular dependencies; Two headers including each other might cause this, if I remember correctly. –  Esa Lakaniemi Dec 17 '12 at 23:01
Show your code. –  melpomene Dec 17 '12 at 23:02
Identifiers with two leading underscores or with one leading underscore and a capital letter are reserved for use by the language implementation. –  Carl Norum Dec 17 '12 at 23:03
@Jimm It sounds like the command line option is combining some form of your source files into one big mess: It might be due to a bug or something but I'd presume that what's happening is that the compiler is processing the #include statements in a way that causes the header to appear several times within the composed source file. Combined with future versions of GCC not including the -combine option, you might wish to refrain from using it, unless necessary. –  Esa Lakaniemi Dec 17 '12 at 23:34
-combine is deprecated in gcc 4.5 and later. Use -flto instead. –  Chris Dodd Dec 18 '12 at 3:06

2 Answers 2

The error is "conflicting types for 'recvmmsg'" rather than just duplicate definition (which would be tolerated if equal). That means your .c source receives two different version of recvmmsg: one by your direct tcpperf.h inclusion and another one by inclusion it via sys/socket.h. I believe you have another version of tcpperf.h elsewhere in inclusion path with different (perhaps older version) recvmmsg.

share|improve this answer

The problem is almost certainly related to -combine. This is a bit of a guess, but in looking at the definition of recvmmsg:

extern int recvmmsg (int __fd, struct mmsghdr *__vmessages,
                     unsigned int __vlen, int __flags,
                     __const struct timespec *__tmo);

note that it takes a struct mmsghdr as an argument. However, while this prototype is unconditional, struct mmsghdr is only defined if __USE_GNU is set:

#ifdef __USE_GNU
/* For `recvmmsg'.  */
struct mmsghdr
    struct msghdr msg_hdr;      /* Actual message header.  */
    unsigned int msg_len;       /* Number of received bytes for the entry.  */

-combine is basically equivalent to concatenating all your files together and then compiling them. Is there any chance that between the text of wrapunix.c and wrapsock.c that GNU_SOURCE is being defined? If that happened, then the first definition of recvmmsg would use a definition of struct mmsghdr that was local to just the prototype, while the second definition would use the real struct. Those two definitions would then be incompatible, which would result in the error message that you got.

share|improve this answer

Your Answer


