hhromic / libe131

libE131: a lightweight C/C++ library for the E1.31 (sACN) protocol
Apache License 2.0
76 stars 19 forks source link

gcc argument order for examples #2

Closed LHolst closed 6 years ago

LHolst commented 6 years ago

i compiled libe131 with success, but the example didnt worked,

i had to position the -le131 argument of the gcc command to the end.

hhromic commented 6 years ago

Hi ! Thanks for reporting and the PR :).

I don't seem to be able to reproduce your issue, can you tell me the version number of your compiler and the exact error shown when you use -le131 at the beginning like in the README? I believe the order shouldn't matter, so is strange.

LHolst commented 6 years ago

gcc --version gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609

gcc -le131 -Wall test_server.c -o test_server 

/tmp/ccSZgUGq.o: In Funktion `main':
test_server.c:(.text+0x22): Nicht definierter Verweis auf `e131_socket'
test_server.c:(.text+0x4c): Nicht definierter Verweis auf `E131_DEFAULT_PORT'
test_server.c:(.text+0x5e): Nicht definierter Verweis auf `e131_bind'
test_server.c:(.text+0x88): Nicht definierter Verweis auf `e131_multicast_join'
test_server.c:(.text+0xd5): Nicht definierter Verweis auf `e131_recv'
test_server.c:(.text+0xfd): Nicht definierter Verweis auf `e131_pkt_validate'
test_server.c:(.text+0x119): Nicht definierter Verweis auf `e131_strerror'
test_server.c:(.text+0x14f): Nicht definierter Verweis auf `e131_pkt_discard'
test_server.c:(.text+0x199): Nicht definierter Verweis auf `e131_pkt_dump'
collect2: error: ld returned 1 exit status
LHolst commented 6 years ago

https://stackoverflow.com/a/14625444 talks about the linker doesnt remember the lib

LHolst commented 6 years ago

ldconfig --version ldconfig (Ubuntu GLIBC 2.23-0ubuntu10) 2.23

LHolst commented 6 years ago

gcc -le131 -Wall -t test_server.c -o test_server

/usr/bin/ld: Modus elf_x86_64
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/5/crtbegin.o
-le131 (/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libe131.so)
/tmp/ccf6Tlc6.o
-lgcc_s (/usr/lib/gcc/x86_64-linux-gnu/5/libgcc_s.so)
/lib/x86_64-linux-gnu/libc.so.6
(/usr/lib/x86_64-linux-gnu/libc_nonshared.a)elf-init.oS
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
-lgcc_s (/usr/lib/gcc/x86_64-linux-gnu/5/libgcc_s.so)
/usr/lib/gcc/x86_64-linux-gnu/5/crtend.o
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crtn.o
/tmp/ccf6Tlc6.o: In Funktion `main':
test_server.c:(.text+0x22): Nicht definierter Verweis auf `e131_socket'
test_server.c:(.text+0x4c): Nicht definierter Verweis auf `E131_DEFAULT_PORT'
test_server.c:(.text+0x5e): Nicht definierter Verweis auf `e131_bind'
test_server.c:(.text+0x88): Nicht definierter Verweis auf `e131_multicast_join'
test_server.c:(.text+0xd5): Nicht definierter Verweis auf `e131_recv'
test_server.c:(.text+0xfd): Nicht definierter Verweis auf `e131_pkt_validate'
test_server.c:(.text+0x119): Nicht definierter Verweis auf `e131_strerror'
test_server.c:(.text+0x14f): Nicht definierter Verweis auf `e131_pkt_discard'
test_server.c:(.text+0x199): Nicht definierter Verweis auf `e131_pkt_dump'
/usr/bin/ld: link errors found, deleting executable `test_server'
collect2: error: ld returned 1 exit status
hhromic commented 6 years ago

Ah I see! The culprit is the linker not the compiler. I have a very recent version so probably it is fixed there and the reason it doesn't fail. As it is no harm for newer versions and it fixes the issue for older versions, I will merge your PR. Thanks!

LHolst commented 6 years ago

seperating compiling and linking works

gcc -c test_server.c

gcc test_server.o -le131 -o test_server

LHolst commented 6 years ago

THX @hhromic