You are not logged in.

#1 2009-06-30 18:25:00

krolden
Member
Registered: 2009-06-30
Posts: 12

[solved] libnet linking issue

Hey all

I was toying with libnet the other day and found that it somehow refuses to link.

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <libnet.h>

int main (int argc, char *argv[])
{
    libnet_t *l;
    char errbuf[LIBNET_ERRBUF_SIZE];

    l = libnet_init(LIBNET_RAW4, argv[1], errbuf);
    if ( l == NULL )
    {
        fprintf(stderr, "libnet_init() failed: %s\n", errbuf);
        exit(EXIT_FAILURE);
    }

    libnet_destroy(l);
    return 0;
}

Compiling is pretty straightforward, but the linking goes amiss.

gcc -Wall -g `libnet-config --defines` -c init.c
gcc -Wall `libnet-config --libs` init.o -o init
init.o: In function `main':
/home/krolden/coding/libnet/init.c:14: undefined reference to `libnet_init'
/home/krolden/coding/libnet/init.c:21: undefined reference to `libnet_destroy'
collect2: ld returned 1 exit status

libnet-config --libs resolves to "-lnet", which should normally take care of the linking against /usr/lib/libnet.a

I'm quite clueless to what the problem can be, so any help on this matter is appreciated.

Last edited by krolden (2009-06-30 20:37:35)

Offline

#2 2009-06-30 19:09:47

Hohoho
Member
Registered: 2007-06-23
Posts: 222

Re: [solved] libnet linking issue

Try this:

gcc -Wall init.o -o init `libnet-config --libs`

Offline

#3 2009-06-30 20:39:26

krolden
Member
Registered: 2009-06-30
Posts: 12

Re: [solved] libnet linking issue

O_O

It works.

So it matters in which order you specify the thing?

In any case, thanks a bunch smile

Offline

Board footer

Powered by FluxBB