Rabbitmq-c library doesn't dynamically linked in Debian 8

1.8k views Asked by At

The goal: make Rabbitmq-c dynamically linked via gcc (https://github.com/alanxz/rabbitmq-c).

Project is called storeman:

#include <stdarg.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <amqp_tcp_socket.h>
#include <amqp.h>
#include <amqp_framing.h>
#include <assert.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>

int main(int argc, char const *const *argv)
{
    amqp_connection_state_t conn;
    conn=amqp_new_connection();
    exit(0); //Everything else is deleted for testing
}

1. Download, compile and install library.

In new build folder inside rabbitmq-c download path:

cmake ..

cmake --build .

cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..

make

make install

Finally it does the following succesfull output:

[ 15%] Built target rabbitmq
...
[100%] Built target test_tables
Install the project...
-- Install configuration: "Release"
-- Up-to-date: /usr/local/lib/x86_64-linux-gnu/pkgconfig/librabbitmq.pc
-- Up-to-date: /usr/local/lib/x86_64-linux-gnu/librabbitmq.so.4.2.1
-- Up-to-date: /usr/local/lib/x86_64-linux-gnu/librabbitmq.so.4
-- Up-to-date: /usr/local/lib/x86_64-linux-gnu/librabbitmq.so
-- Up-to-date: /usr/local/lib/x86_64-linux-gnu/librabbitmq.a
-- Up-to-date: /usr/local/include/amqp.h
-- Up-to-date: /usr/local/include/amqp_framing.h
-- Up-to-date: /usr/local/include/amqp_tcp_socket.h
-- Up-to-date: /usr/local/include/amqp_ssl_socket.h

The library files are installed into

  • /usr/local/lib/x86_64-linux-gnu/ (librabbitmq.so and librabbitmq.so.4 points as links to librabbitmq.so.4.2.1, and there is librabbitmq.a)

  • /usr/local/include/, where all needed header files are resides (amqp.h amqp_framing.h amqp_ssl_socket.h amqp_tcp_socket.h)

2. Use gcc.

gcc -Wall -I/usr/local/include -L/usr/local/lib/x86_64-linux-gnu -o storeman storeman.c -lrabbitmq

GCC exits with:

error while loading shared libraries: librabbitmq.so.4: cannot open shared object file: No such file or directory

In the same time it may succesfully be compiled as static, using librabbitmq.a, that confuses me a lot... Will be very gratefull for any help.

1

There are 1 answers

1
John Thompson On

It looks to me like the issue may be that file /etc/ld.so.conf.d/rabbitmq.conf is missing the .../lib/... subdirectory in its content. When I update that file's content to this it works for me (finds the rabbitmq shared lib):

/usr/local/lib/x86_64-linux-gnu 

Note, run sudo ldconfig after saving the change.

This appears to be a rabbitmq git installation bug - I cloned and built from branch master on Feb 22, 2018 on Ubu-17.