Robson
asked on
Linking problem
Hello.
While trying to check why my ./configure script cannot find my libraries,
I found this really confusing problem. I've got a libutil library in /usr/local/lib. When I compile a program
gcc -o test test.cpp -lutil -L/usr/local/lib
it goes just fine. But when instead i export LD_LIBRARY_PATH=/usr/local /lib and remove -L option, it fails (and also fails when ./configure checks for libraries, as I've seen in config.log). I've tried to putj /usr/local/lib in ld.so.conf and run ldconfig with no results.
My system is RH 7.2
While trying to check why my ./configure script cannot find my libraries,
I found this really confusing problem. I've got a libutil library in /usr/local/lib. When I compile a program
gcc -o test test.cpp -lutil -L/usr/local/lib
it goes just fine. But when instead i export LD_LIBRARY_PATH=/usr/local
My system is RH 7.2
It worked because the system library libutil is in /usr/lib or similar. The first directory searched is the one specified by -L (and in order, too). You shouldn't use standard names for the exact reason you posted this question.
More importantly, post a request in CS to have this question PAQ'd, and refund your points (with a link to this question). Since you answered it yourself, you don't need pay for it.
More importantly, post a request in CS to have this question PAQ'd, and refund your points (with a link to this question). Since you answered it yourself, you don't need pay for it.
ld does not use LD_LIBRARY_PATH for searching libraries (except Sun's bundled /usr/ccs/bin/ld)
So gcc -o test test.cpp -lutil -L/usr/local/lib
works fine 'cause you specified a path to the libutil with -L.
When you omit -L, the default settings of library search pathes apply, and that contains /lib and /usr/lib where it finds libutil system library (if installed).
Check with gcc -v ...
So gcc -o test test.cpp -lutil -L/usr/local/lib
works fine 'cause you specified a path to the libutil with -L.
When you omit -L, the default settings of library search pathes apply, and that contains /lib and /usr/lib where it finds libutil system library (if installed).
Check with gcc -v ...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks IainHere! I'll do that.
To ahoffmann: setting LD_LIBRARY_PATH (after rewriting /etc/ld.so.conf) was my first act of desperation. Second act was tracking linking process with 'strace' :-) That's how I found that ld loads /usr/lib/libutil.so instead of /usr/local/lib/libutil.so
To ahoffmann: setting LD_LIBRARY_PATH (after rewriting /etc/ld.so.conf) was my first act of desperation. Second act was tracking linking process with 'strace' :-) That's how I found that ld loads /usr/lib/libutil.so instead of /usr/local/lib/libutil.so
ASKER
And now: first expert who explains why one should not create librares named as standard libraries and why compilation worked with -L option will get at least B grade (I already know it, but I cannot pass points to myself :-)