imaginevision / libssp

MIT License
21 stars 10 forks source link

Linux compilation error: "collect2: error: ld returned 1 exit status" #4

Open darkvertex opened 4 years ago

darkvertex commented 4 years ago

Do these errors say anything to you?

$ cd example/linux/
$ make all
g++ ../libssp_test.cpp -std=c++11 -L../../lib/linux_x64/ -lssp -lpthread -I../../include/ -I../../include/libuv/include/ -lrt -o libssp_test
../libssp_test.cpp: In function ‘void on_264_1(imf::SspH264Data*)’:
../libssp_test.cpp:24:91: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘uint64_t {aka long unsigned int}’ [-Wformat=]
  printf("on 1 264 [%d] [%lld] [%d] [%d]\n", h264->frm_no, h264->pts, h264->type, h264->len);
                                                                                           ^
../libssp_test.cpp:24:91: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
../libssp_test.cpp: In function ‘void on_264_2(imf::SspH264Data*)’:
../libssp_test.cpp:29:91: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘uint64_t {aka long unsigned int}’ [-Wformat=]
  printf("on 2 264 [%d] [%lld] [%d] [%d]\n", h264->frm_no, h264->pts, h264->type, h264->len);
                                                                                           ^
../libssp_test.cpp:29:91: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
/tmp/ccVSbn5M.o: In function `setup(imf::Loop*)':
libssp_test.cpp:(.text+0x287): undefined reference to `imf::SspClient::SspClient(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, imf::Loop*, unsigned long, unsigned short, unsigned int)'
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1

I have g++ 5.4.0 on Ubuntu 16.04 LTS.

Curiously, at work on a CentOS 7 machine I was able to compile it just fine.

What are the real minimum requirements for a successful build? Which versions of what?

jlucidar commented 4 years ago

Same Error here on ubuntu18.04 with g++ 7.4.0 :

g++ ../libssp_test.cpp -std=c++11 -L../../lib/linux_x64/ -lssp -lpthread -I../../include/ -I../../include/libuv/include/ -lrt -o libssp_test
../libssp_test.cpp: In function ‘void on_264_1(imf::SspH264Data*)’:
../libssp_test.cpp:24:91: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘uint64_t {aka long unsigned int}’ [-Wformat=]
  printf("on 1 264 [%d] [%lld] [%d] [%d]\n", h264->frm_no, h264->pts, h264->type, h264->len);
                                                           ~~~~~~~~~                       ^
../libssp_test.cpp:24:91: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
../libssp_test.cpp: In function ‘void on_264_2(imf::SspH264Data*)’:
../libssp_test.cpp:29:91: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘uint64_t {aka long unsigned int}’ [-Wformat=]
  printf("on 2 264 [%d] [%lld] [%d] [%d]\n", h264->frm_no, h264->pts, h264->type, h264->len);
                                                           ~~~~~~~~~                       ^
../libssp_test.cpp:29:91: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
/usr/bin/ld: ../../lib/linux_x64//libssp.a(timer.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(uv-common.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(async.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(core.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(fs-poll.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(inet.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(linux-core.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(linux-inotify.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(loop.c.o): relocation R_X86_64_32 against hidden symbol `uv__work_done' can not be used when making a PIE object
/usr/bin/ld: ../../lib/linux_x64//libssp.a(pipe.c.o): relocation R_X86_64_32S against hidden symbol `uv__server_io' can not be used when making a PIE object
/usr/bin/ld: ../../lib/linux_x64//libssp.a(poll.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(process.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(signal.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(stream.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(tcp.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(thread.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(threadpool.c.o): relocation R_X86_64_32 against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(udp.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(fs.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/tmp/ccgq4msZ.o: In function `setup(imf::Loop*)':
libssp_test.cpp:(.text+0x1c1): undefined reference to `imf::SspClient::SspClient(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, imf::Loop*, unsigned long, unsigned short, unsigned int)'
/usr/bin/ld: final link failed: Symbol needs debug section which does not exist
collect2: erg++ ../libssp_test.cpp -std=c++11 -L../../lib/linux_x64/ -lssp -lpthread -I../../include/ -I../../include/libuv/include/ -lrt -o libssp_test
../libssp_test.cpp: In function ‘void on_264_1(imf::SspH264Data*)’:
../libssp_test.cpp:24:91: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘uint64_t {aka long unsigned int}’ [-Wformat=]
  printf("on 1 264 [%d] [%lld] [%d] [%d]\n", h264->frm_no, h264->pts, h264->type, h264->len);
                                                           ~~~~~~~~~                       ^
../libssp_test.cpp:24:91: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
../libssp_test.cpp: In function ‘void on_264_2(imf::SspH264Data*)’:
../libssp_test.cpp:29:91: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘uint64_t {aka long unsigned int}’ [-Wformat=]
  printf("on 2 264 [%d] [%lld] [%d] [%d]\n", h264->frm_no, h264->pts, h264->type, h264->len);
                                                           ~~~~~~~~~                       ^
../libssp_test.cpp:29:91: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
/usr/bin/ld: ../../lib/linux_x64//libssp.a(timer.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(uv-common.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(async.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(core.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(fs-poll.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(inet.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(linux-core.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(linux-inotify.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(loop.c.o): relocation R_X86_64_32 against hidden symbol `uv__work_done' can not be used when making a PIE object
/usr/bin/ld: ../../lib/linux_x64//libssp.a(pipe.c.o): relocation R_X86_64_32S against hidden symbol `uv__server_io' can not be used when making a PIE object
/usr/bin/ld: ../../lib/linux_x64//libssp.a(poll.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(process.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(signal.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(stream.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(tcp.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(thread.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(threadpool.c.o): relocation R_X86_64_32 against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(udp.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux_x64//libssp.a(fs.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/tmp/ccgq4msZ.o: In function `setup(imf::Loop*)':
libssp_test.cpp:(.text+0x1c1): undefined reference to `imf::SspClient::SspClient(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, imf::Loop*, unsigned long, unsigned short, unsigned int)'
/usr/bin/ld: final link failed: Symbol needs debug section which does not exist
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1
ror: ld returned 1 exit status
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1
darkvertex commented 4 years ago

@jlucidar If it helps you, I wrote myself this Dockerfile that can compile it successfully and consistently:

FROM centos:7
RUN yum install -y make gcc-c++-4.8.5
COPY . ./libssp/
WORKDIR ./libssp/example/linux
RUN make all && chmod 777 libssp_test
CMD ./libssp_test

(I didn't check if the resulting file works as-is in Ubuntu though.)

jlucidar commented 4 years ago

Yup, did the same ^^ It works directly in Ubuntu ;)

secit commented 4 years ago

Use g++ version 4.8.5, then it should compile just fine.