LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   conflicting redeclaration of sys/types.h and linux/types.h (https://www.linuxquestions.org/questions/programming-9/conflicting-redeclaration-of-sys-types-h-and-linux-types-h-641052/)

schmil 05-09-2008 09:01 AM

conflicting redeclaration of sys/types.h and linux/types.h
 
Hi,

I wrote a program that uses both linux/if.h and netinet/ip.h
linux/if.h uses linux/types.h which conflict with sys/types.h used by netinet/ip.h

Any idea how to solve this problem?

Thanks
Schmil

compilation errors

/usr/include/sys/types.h:46: error: conflicting declaration ‘typedef __loff_t loff_t’
/usr/include/linux/types.h:30: error: ‘loff_t’ has a previous declaration as ‘typedef __kernel_loff_t loff_t’
/usr/include/sys/types.h:62: error: conflicting declaration ‘typedef __dev_t dev_t’
/usr/include/linux/types.h:13: error: ‘dev_t’ has a previous declaration as ‘typedef __kernel_dev_t dev_t’
/usr/include/time.h:105: error: conflicting declaration ‘typedef void* timer_t’
/usr/include/linux/types.h:22: error: ‘timer_t’ has a previous declaration as ‘typedef __kernel_timer_t timer_t’
/usr/include/sys/types.h:198: error: conflicting declaration ‘typedef long int int64_t’
/usr/include/linux/types.h:98: error: ‘int64_t’ has a previous declaration as ‘typedef __s64 int64_t’
/usr/include/sys/types.h:204: error: conflicting declaration ‘typedef long unsigned int u_int64_t’
/usr/include/linux/types.h:97: error: ‘u_int64_t’ has a previous declaration as ‘typedef __u64 u_int64_t’
/usr/include/sys/select.h:78: error: conflicting declaration ‘typedef struct fd_set fd_set’
/usr/include/linux/types.h:12: error: ‘fd_set’ has a previous declaration as ‘typedef struct __kernel_fd_set fd_set’
/usr/include/sys/types.h:235: error: conflicting declaration ‘typedef __blkcnt_t blkcnt_t’
/usr/include/linux/types.h:124: error: ‘blkcnt_t’ has a previous declaration as ‘typedef long unsigned int blkcnt_t’
/usr/include/bits/uio.h:44: error: redefinition of ‘struct iovec’
/usr/include/linux/uio.h:16: error: previous definition of ‘struct iovec’
/usr/include/bits/socket.h:150: error: redefinition of ‘struct sockaddr’
/usr/include/linux/socket.h:38: error: previous definition of ‘struct sockaddr’
/usr/include/bits/socket.h:167: error: redefinition of ‘struct __kernel_sockaddr_storage’
/usr/include/linux/socket.h:11: error: previous definition of ‘struct __kernel_sockaddr_storage’
/usr/include/bits/socket.h:178: error: expected identifier before numeric constant
/usr/include/bits/socket.h:178: error: expected `}' before numeric constant
/usr/include/bits/socket.h:178: error: expected unqualified-id before numeric constant
/usr/include/bits/socket.h:225: error: redefinition of ‘struct msghdr’
/usr/include/linux/socket.h:56: error: previous definition of ‘struct msghdr’
/usr/include/bits/socket.h:243: error: redefinition of ‘struct cmsghdr’
/usr/include/linux/socket.h:72: error: previous definition of ‘struct cmsghdr’
/usr/include/bits/socket.h:302: error: expected identifier before numeric constant
/usr/include/bits/socket.h:302: error: expected `}' before numeric constant
/usr/include/bits/socket.h:302: error: expected unqualified-id before numeric constant
/usr/include/bits/socket.h:308: error: expected declaration before ‘}’ token

paulsm4 05-09-2008 11:42 AM

Hi -

I don't get any conflict. Here's an example:
Code:

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <netinet/ip.h>

int
main ()
{
  printf ("Hello world!\n");
}
  <= This compiles without error

Perhaps you might consider reinstalling/updating your GCC development package?

Also: make sure you haven't somehow mixed kernel source headers (which should be under "/usr/src/linux*") with user (non-kernel) headers (which should be under "/usr/include").

schmil 05-10-2008 05:41 PM

Hi,

How can I get the headers mixed, I icluded them as following:
#include <linux/if.h>
#include <netinet/ip.h>

paulsm4 05-10-2008 06:38 PM

Please try this:

1. Try compiling the above "Hello world".

2. If it fails with the same error, then consider de-installing your current gcc-dev package and re-installing (the latest/greatest) version.

You should be able to use the standard "<linux/if.h>" and "<netinet/ip.h>" headers together with no problem.

I suspect the problem is configuration, with the gcc-dev installation you have on your system.

IMHO .. PSM

schmil 05-17-2008 06:03 PM

I used linux/ip.h and that solved the problem
But I'll try to reinstall GCC later

Thanks

schmil 07-20-2008 04:15 PM

I Though i solvedit
 
I thought that I solved it when I changed to linux/ip.h instead of netinet/ip.h
but lately I got into more trouble.
When I compile the small hello program below I don't have any problems
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <netinet/ip.h>

int
main ()
{
printf ("Hello world!\n");
}

Both programs use the same includes but only the Hello program compiles without errors????

jsarao 12-11-2008 02:02 PM

I had the same problem. turns out it was an #include somewhere else in my project.

Try this:

do a complete search for "types.h" in all files in your project

I then made all of them

#include <sys/types.h>

and everything compiled.


All times are GMT -5. The time now is 05:07 AM.