When you compile your program, you must specify gcc not only the name of the library you are going to use ( -lrabbimtq ), but also the path (i.e. the directory) in which to look for the library from ( -L/path/to/rabbitmq-c ) during binding. gcc (or the linker) will always look for some default directories, but your rabbitmq-c library is not available in these directories.
So your gcc command line should look like this:
gcc -I/path/to/rabbitmq-c-header-dir -L/path/to/rabbitmq-c-lib-dir -o j_test test.c -lrabbitmq
Note that you need to specify the location of the header ( -I ) files and that the -lrabbitmq position is -lrabbitmq .
In the example below, the ~/src/rabbitmq-c directory is the location of my rabbitmq-c clone.
Location of headers and shared library:
~/src/rabbitmq-c$ find . -name amqp.h ./librabbitmq/amqp.h ~/src/rabbitmq-c$ find . -name librabbitmq.so ./librabbitmq/.libs/librabbitmq.so ~/src/rabbitmq-c$
Compiling and linking your sample program:
~/src/rabbitmq-c$ cat > stacko.c #include <amqp.h> #include <amqp_framing.h> int main(int argc, char const * const *argv) { amqp_connection_state_t conn; conn = amqp_new_connection(); amqp_destroy_connection(conn); return 0; } ~/src/rabbitmq-c$ gcc -Ilibrabbitmq -g -Wall -c stacko.c ~/src/rabbitmq-c$ gcc -Llibrabbitmq/.libs -g -Wall -o stacko stacko.o -lrabbitmq ~/src/rabbitmq-c$
In shared libraries, you must also specify at runtime where the libraries will be found:
~/src/rabbitmq-c$ ./stacko ./stacko: error while loading shared libraries: librabbitmq.so.0: cannot open shared object file: No such file or directory ~/src/rabbitmq-c$ LD_LIBRARY_PATH=librabbitmq/.libs ./stacko ~/src/rabbitmq-c$
You can check which libraries the executable uses with ldd :
~/src/rabbitmq-c$ ldd ./stacko linux-gate.so.1 => (0x00d7d000) librabbitmq.so.0 => not found libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00396000) /lib/ld-linux.so.2 (0x002d6000) ~/src/rabbitmq-c$ LD_LIBRARY_PATH=librabbitmq/.libs ldd ./stacko linux-gate.so.1 => (0x001c8000) librabbitmq.so.0 => librabbitmq/.libs/librabbitmq.so.0 (0x00f77000) libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x001c9000) /lib/ld-linux.so.2 (0x00cc3000) ~/src/rabbitmq-c$
See also g ++: how to specify library path preference? .