3

I'm having trouble "installing" a shared library I download online. The library name is run time access (http://www.runtimeaccess.com/). In the quick start guide, they explain how to use the library using -L when compiling to define the library location and exporting the LD_LIBRARY_PATH env variable after adding the path of the library dir. First of all why do you need to define the lib location twice? using -L and LD_Library_PATH env variable?

Second part. I'm trying to avoid passing these arguments and also avoiding modification of the LD_LIBRARY_PATH env, so all I have to do is compile like so:

$ gcc myapp.c -lrtadb

so I would like to include the lib as part of the system lib. So I copied the whole rta-0.8.1 folder to /usr/local/lib/rta-0.8.1 and then add a /etc/ld.conf.d/rtadb.conf file containing the path of the library directory /usr/local/lib/rta-0.8.1/src in there.

$ cat /etc/ld.so.conf.d/rtadb.conf 
#rta (run time access) lib
/usr/local/lib/rta-0.8.1/src

and then I ran sudo ldconfig to update the shared library list - but no luck. When I try to compile my code, the library is not found:

$gcc myappdb.c -lrtadb
/usr/bin/ld: cannot find -lrtadb
collect2: ld returned 1 exit status

What am I doing wrong here?

here is the list of files in /usr/local/lib/rta-0.8.1/src

user@ubuntu:/usr/local/lib/rta-0.8.1/src$ ls -l
total 724
-rw-r--r-- 1 root root  24994 2012-11-14 10:49 api.c
-rw-r--r-- 1 root root  26132 2012-11-14 11:07 api.o
-rw-r--r-- 1 root root  62634 2012-11-14 10:49 do_sql.c
-rw-r--r-- 1 root root   5419 2012-11-14 10:49 do_sql.h
-rw-r--r-- 1 root root  41184 2012-11-14 11:07 do_sql.o
-rw-r--r-- 1 root root 149186 2012-11-14 11:07 librtadb.a
lrwxrwxrwx 1 root root     15 2012-11-14 11:07 librtadb.so -> librtadb.so.3.0
lrwxrwxrwx 1 root root     15 2012-11-14 11:07 librtadb.so.3 -> librtadb.so.3.0
-rwxr-xr-x 1 root root 117749 2012-11-14 11:07 librtadb.so.3.0
-rw-r--r-- 1 root root   2387 2012-11-14 10:49 Makefile
-rw-r--r-- 1 root root  10962 2012-11-14 11:07 parse.output
-rw-r--r-- 1 root root  21929 2012-11-14 11:07 parse.tab.c
-rw-r--r-- 1 root root    425 2012-11-14 11:07 parse.tab.h
-rw-r--r-- 1 root root  25064 2012-11-14 11:07 parse.tab.o
-rw-r--r-- 1 root root   6711 2012-11-14 10:49 parse.y
-rw-r--r-- 1 root root  46636 2012-11-14 10:49 rta.h
-rw-r--r-- 1 root root  31551 2012-11-14 10:49 rtatables.c
-rw-r--r-- 1 root root  17028 2012-11-14 11:07 rtatables.o
-rw-r--r-- 1 root root  58843 2012-11-14 11:07 token.c
-rw-r--r-- 1 root root   6291 2012-11-14 10:49 token.l
-rw-r--r-- 1 root root  37996 2012-11-14 11:07 token.o

btw, I'm running Ubuntu 10.04 LTS

thank you.

edit: if your new to this info read link below: http://www.tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

1 Answer 1

3

You need to tell the ld where to look for the library, since it is not in one of the default directories. Since the linker is called by gcc, use the latter's -L option.

gcc -lrtadb -L/usr/local/lib/rta-0.8.1/src

should do it in your case.

4
  • But I placed the library path as part of the default lib directories in the /etc/ld.so.conf.d/ files.
    – ArmenB
    Nov 14, 2012 at 21:29
  • 2
    /etc/ld.conf* is information for the runtime linker ldd, that resolves what shared libraries to load in application address space. ld is a compile time linker - it actually embeds the references to the required symbols into the binary.
    – peterph
    Nov 14, 2012 at 21:53
  • ok that explains it.Thx, But in any case, how can I avoid explicitly defining the library path. example if I use -sdl or -pthead I don't specify the location of the library.
    – ArmenB
    Nov 14, 2012 at 21:58
  • 1
    because they live in "standard" directories (/lib*, /usr/lib*, and probably /usr/local/lib*). If you move your library there, it should start working without the -L option. But be careful about that, since it would likely pollute your system in a sense, that the files would not be owned by any packages (assuming you are using a distribution with a packaging system).
    – peterph
    Nov 14, 2012 at 22:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .