alanxz / rabbitmq-c

RabbitMQ C client
MIT License
1.77k stars 672 forks source link

target 'examples/amqp_ssl_connect' failed @ [38%]Linking C executable amqp_ssl_connect #548

Open srbiotik opened 5 years ago

srbiotik commented 5 years ago

Trying to build rabbitmq-c v0.9.0 on

os = Ubuntu 16.04 gcc = 5.4.0 make = GNU Make 4.1 cmake = version 3.5.1 openssl = http://www.openssl.org/source/openssl-1.1.0g.tar.gz.md5

Failing @

$ cmake --build .
[  1%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_framing.c.o
[  2%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_api.c.o
[  3%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_connection.c.o
[  4%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_mem.c.o
[  5%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_socket.c.o
[  6%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_table.c.o
[  7%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_url.c.o
[  8%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_tcp_socket.c.o
[ 10%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_time.c.o
[ 11%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_consumer.c.o
[ 12%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_openssl.c.o
[ 13%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_openssl_hostname_validation.c.o
[ 14%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_hostcheck.c.o
[ 15%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_openssl_bio.c.o
[ 16%] Linking C shared library librabbitmq.so
[ 16%] Built target rabbitmq
[ 17%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_framing.c.o
[ 19%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_api.c.o
[ 20%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_connection.c.o
[ 21%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_mem.c.o
[ 22%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_socket.c.o
[ 23%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_table.c.o
[ 24%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_url.c.o
[ 25%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_tcp_socket.c.o
[ 26%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_time.c.o
[ 28%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_consumer.c.o
[ 29%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_openssl.c.o
[ 30%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_openssl_hostname_validation.c.o
[ 31%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_hostcheck.c.o
[ 32%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_openssl_bio.c.o
[ 33%] Linking C static library librabbitmq.a
[ 33%] Built target rabbitmq-static
[ 34%] Building C object examples/CMakeFiles/amqp_ssl_connect.dir/amqp_ssl_connect.c.o
[ 35%] Building C object examples/CMakeFiles/amqp_ssl_connect.dir/utils.c.o
[ 37%] Building C object examples/CMakeFiles/amqp_ssl_connect.dir/unix/platform_utils.c.o
[ 38%] Linking C executable amqp_ssl_connect
../librabbitmq/librabbitmq.so.4.3.0: undefined reference to `dlopen'
../librabbitmq/librabbitmq.so.4.3.0: undefined reference to `dlclose'
../librabbitmq/librabbitmq.so.4.3.0: undefined reference to `dlerror'
../librabbitmq/librabbitmq.so.4.3.0: undefined reference to `dlsym'
../librabbitmq/librabbitmq.so.4.3.0: undefined reference to `dladdr'
collect2: error: ld returned 1 exit status
examples/CMakeFiles/amqp_ssl_connect.dir/build.make:149: recipe for target 'examples/amqp_ssl_connect' failed
make[2]: *** [examples/amqp_ssl_connect] Error 1
CMakeFiles/Makefile2:199: recipe for target 'examples/CMakeFiles/amqp_ssl_connect.dir/all' failed
make[1]: *** [examples/CMakeFiles/amqp_ssl_connect.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
shivamMg commented 4 years ago

I got the same error while compiling on an arm7l device. To fix it I added ${CMAKE_DL_LIBS} to two statements in librabbitmq/CMakeLists.txt:

target_link_libraries(rabbitmq ${RMQ_LIBRARIES} ${CMAKE_DL_LIBS})
...
target_link_libraries(rabbitmq-static ${RMQ_LIBRARIES} ${CMAKE_DL_LIBS})

My device:

$ uname -a
Linux ubuntu 4.15.0-1031-raspi2 #33-Ubuntu SMP PREEMPT Wed Jan 16 09:58:55 UTC 2019 armv7l armv7l armv7l GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:    18.04
Codename:   bionic

I'm not sure if it's the correct fix. Will create a PR if it is. Would like to get your opinion on this @alanxz