0

I have problem with linking libevent into my c project on ubuntu 14.04 LTS Server. Everything works fine on ArchLinux and Centos7 (both ubuntu and centos I run on virtual machine).
These is my Makefile:

TARGET: opoznienia

CFLAGS = -Wall -O2 --std=c11 -D DEBUG=1 $(shell pkg-config --cflags libevent_pthreads) -pthread -Wextra
LFLAGS = -Wall $(shell pkg-config --libs libevent_pthreads) -pthread -Wextra
OFILES = main.o err.o dropnobody.o ... <-- tl;tr

opoznienia: $(OFILES)
    $(CC) $(LFLAGS) $^ -o $@

.PHONY: clean TARGET
clean:
    rm -f opoznienia *.o *~ *.bak


On ubuntu I get error:

telnet_server.c:(.text+0xfc): undefined reference to `event_new'

1 Answers1

1

GNU linker parses the object files arguments (.o .a .so) from left to right trying to match all the undefined symbols. And the order of object files is really important here, because GNU linker 'forgets' any symbols if they were not used by any object file passed in the argument list before the current object file.

In your case try changing the linkage order form:

$(CC) $(LFLAGS) $^ -o $@

To:

$(CC) $^ $(LFLAGS) -o $@

Let us know if this helps.

sqr163
  • 1,074
  • 13
  • 24