Compile error from included headers

Thread Tools Search this Thread
Top Forums Programming Compile error from included headers
# 1  
Old 08-31-2011
Compile error from included headers

Hello, I have an error when I include the socket.h linux header and compile with gcc.

In file included from /usr/include/sys/socket.h:40:0,
                 from test.c:17:
/usr/include/bits/socket.h:217:5: error: expected identifier before numeric constant

In test.c:17:
#include <sys/socket.h>

What's the cause and how can I resolve it?

Last edited by pludi; 08-31-2011 at 07:52 AM..
# 2  
Old 08-31-2011
That's nowhere near enough data for anyone to help you.


1. Your test code. All of it.
2. Your compile options/commands. All of them.
3. Your OS and version. The exact OS and version. "Linux" is not an OS - it is a kernel, with LOTS of versions.
# 3  
Old 08-31-2011
Ok sorry, I use ubuntu 11.04 (kernel 2.6.38-11) this is the code:
#include <stdio.h>
#include <stdlib.h>
#include <libnetfilter_log/libipulog.h>
#include <netinet/ip.h>

#define MYBUFSIZ 2048
#define GROUP 1
#define COUNT 100

int main(int argc, char *argv[]) {
    struct ipulog_handle *h;
    unsigned char* buf;
    int len;
    ulog_packet_msg_t *upkt;
    int i;

    /* allocate a receive buffer */
    buf = (unsigned char *) malloc(MYBUFSIZ);
    if (!buf)

    /* create ipulog handle */
    h = ipulog_create_handle(ipulog_group2gmask(GROUP), 65535);
    if (!h) {
        /* if some error occurrs, print it to stderr */
        ipulog_perror( NULL);

    /* loop receiving packets and handling them over to handle_packet */
    for (i = 0; i < COUNT; i++) {
        len = ipulog_read(h, buf, MYBUFSIZ, 1);
        if (len <= 0) {
            ipulog_perror("ulog_test: short read");
        printf("%d bytes received\n", len);
        while (upkt = ipulog_get_packet(h, buf, len)) {
            struct iphdr *iph = (struct iphdr *) upkt->payload;
            printf("%d\n", iph->saddr);

    /* just to give it a cleaner look */
    return 0;

And I compile simply with
gcc test.c

This is the related error from the compiler:
In file included from /usr/include/sys/socket.h:40:0,
                 from /usr/include/netinet/in.h:25,
                 from /usr/include/netinet/ip.h:25,
                 from test.c:4:
/usr/include/bits/socket.h:217:5: error: expected identifier before numeric constant

Last edited by pludi; 08-31-2011 at 08:31 AM..
# 4  
Old 08-31-2011
#include <libnetfilter_log/libipulog.h>
#include <netinet/ip.h>

#include <netinet/ip.h>
#include <libnetfilter_log/libipulog.h>

The reason is that libipulog.h defines a macro MSG_TRUNC, which then screws up an enum in bits/socket.h, leading to that error. If you include netinet/ip.h first, that enum passed the pre-processor correctly.

Also, you'll need to explicitly tell gcc to link to libnetfilter_log_libipulog, otherwise you'll get undefined reference errors.
This User Gave Thanks to pludi For This Post:
# 5  
Old 08-31-2011
Thanks pludi now it works! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Slackware

Error compile NFS

Tryng to compile nfs-utils to latest packages but.. make: Entering directory `/tmp/nfs-utils-1.2.8/utils/gssd' /bin/sh ../../libtool --tag=CC --mode=link gcc -Wall -Wextra -Wstrict-prototypes -pipe -O2 -fPIC -I/usr/kerberos/include -I/usr/kerberos/include -O2 -fPIC -ltirpc -o gssd... (4 Replies)
Discussion started by: Linusolaradm1
4 Replies

2. Ubuntu

Kernel compile error

Hi I'm compiling a real-time kernel in linux, but after I type make bzImage things end with this: (Things going well doing CC and things).... CC arch/x86/kernel/kgdb.o CC arch/x86/kernel/vm86_32.o CC arch/x86/kernel/early_printk.o CC arch/x86/kernel/ipipe.o... (2 Replies)
Discussion started by: mdop
2 Replies

3. UNIX for Dummies Questions & Answers

Compiling gcc to compile make to compile yaboot

I have just installed OpenBSD on a 333MHz PPC iMac G3. It has a 6GB HDD that has been partitioned as 1GB MacOS 8.5.1, 3GB MacOS X 10.3.9, 2GB OpenBSD 4.8. I now need to install a bootloader so that my computer can recognize the OpenBSD partition at startup. I have been trying to install... (0 Replies)
Discussion started by: t04st3r
0 Replies

4. Solaris

Samba 3.5.4 compile error

Hello! I am trying install samba 3.5.4. and following this instruction from the source package. So, there are my steps: 1 cd ../samba-3.5.4/source3 2 ./configure (without any arguments) and when i run make it returns error .................................................... Compiling... (2 Replies)
Discussion started by: zhum
2 Replies

5. Shell Programming and Scripting

Merging of files with different headers to make combined headers file

Hi , I have a typical situation. I have 4 files and with different headers (number of headers is varible ). I need to make such a merged file which will have headers combined from all files (comman coluns should appear once only). For example - File 1 H1|H2|H3|H4 11|12|13|14 21|22|23|23... (1 Reply)
Discussion started by: marut_ashu
1 Replies

6. Shell Programming and Scripting

Remove text between headers while leaving headers intact

Hi, I'm trying to strip all lines between two headers in a file: ### BEGIN ### Text to remove, contains all kinds of characters ... (Germany)=http://www.antispyware-downloadserver.c om/updates/ #2... (3 Replies)
Discussion started by: Trones
3 Replies

7. Programming

C compile error

hello can anyone help? :confused: i make a C code in FreeBSD 5.4 and it succeed to run the program requires connection to mysql server when i try to compile it under solaris i get this error message ld: fatal: file ./lib/ wrong ELF machine type: EM_386 why? and how to... (3 Replies)
Discussion started by: kuampang
3 Replies

8. Programming

compile error message

i was trying to compile a c program and got the error below. i need help on how to resolve this $ make -ef putput `if ; then echo getinf.awk ; else echo getora.awk;fi` EI.sql `if ; then echo esql -static ; else echo esqlo8i;fi` -O -I. -c EI`if ; then echo .ec; else echo... (4 Replies)
Discussion started by: putput
4 Replies

9. Programming

Compile error

Dear All I have a program writen in C and test in Unix. Now, I am try to run this program in windows 2000. I am receiving an error ]_getopt is not define. I will appreciate if any one can help explain to me why this problem is hapening and to slove this problem. Thank you (9 Replies)
Discussion started by: coulio
9 Replies

10. Programming

Error in compile C by gcc

Hi all, I compile my c program and get following result hrnpfc01.c:1387: stray '\' in program hrnpfc01.c:1387: parse error before `,' hrnpfc01.c:1388: stray '\' in program hrnpfc01.c:1388: parse error before `,' hrnpfc01.c:1396: stray '\' in program hrnpfc01.c:1396: parse error before... (4 Replies)
Discussion started by: zico
4 Replies
Login or Register to Ask a Question