This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

-L and shared libraries

Hi all,

I bumped into an issue this afternoon (european time) with gcc and the linking of dynamic libraries. It is not the first time I run into it but this time I will try to get an answer from you gurus. I browsed the archive for this list and the closest I could get was a message in 2003, looking like:

> We want to set up gcc to search /usr/local/GCC/lib when compiling
> *without* having to set up LD_LIBRARY_PATH.  Is there a way of doing
> this?

-Ldir Add directory dir to the list of directories to be searched for
I do not fully agree with the answer. It seems to me that -Ldir answers to only part of the problem (on my Linux-x86 configutation, at least).

I hope confirmation or pointing to section of the man pages :-)

My situation is,
> gcc bar.o -o bar.exe -lfoo
does work because is in the default search path (/usr/lib/ exists).

But I want to use the version of foo which is in /usr/local/GCC/lib. So I use:

gcc -L/usr/local/GCC/lib bar.o -o bar.exe -lfoo

This also compiles smoothly. I note that it would also compile ok if there was no in the /usr/local/GCC/lib. There would also be no further problem if both versions of libfoo was static objects.

*But*, coming back to my .so case, if I try
> ldd bar.exe
I see that the reference to is in /usr/lib. :-o.
I have to 1) either set the LD_RUN_PATH but it is too tedious as I have several other libraries and I am lazy or 2) use:

> gcc -L/usr/local/GCC/lib bar.o -Wl,-rpath=/usr/local/GCC/lib -o bar.exe -lfoo
Then ldd gives ok result.

So now my questions:
1) what controls this behaviour (that the dynamic loader still tries to load from the default directories)? Is it a feature of gnu ld? Is it different on other architecture?
2) should not the semantic of -L be exactly that? If you are to link against a dynamic library, pass -rpath=libdir to the linker.
3) could we imagine a new flag (-LLdir) that would automatically pass the -rpath=dir info to ld (of course only if libfoo is a dynamic libary)? That would be a cool feature, wouldn't it?

Et voila. Sorry if it is FAQ or solved elsewhere. I definitely wait for some enlightments... Thomas

PS: Please answer to me as I am not subscribed to the list.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]