Bug 326 - -L path has lower priority than built-in path
Summary: -L path has lower priority than built-in path
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 2.95.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2000-06-15 04:46 UTC by mtsirkin
Modified: 2003-07-25 17:33 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mtsirkin 2000-06-15 04:46:01 UTC
I found that the directories specified by the configuration 
of GCC or by LIBRARY_PATH variable override these specified 
with -L command line switch.
example:

Release:
gcc-2.95.2

Environment:
/tmp>gcc -dumpspecs
*asm:
%{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Yd,*} %{Wa,*:%*}

*asm_final:
%|

*cpp:
%(cpp_cpu) %{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}

*cc1:
%(cc1_cpu) %{profile:-p}

*cc1plus:


*endfile:
%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s

*link:
-m elf_i386 %{shared:-shared}   %{!shared:     %{!ibcs:       %{!static:        %{rdynamic:-export-dynamic}       %{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.2}}  %{static:-static}}}

*lib:
%{shared: -lc}    %{!shared: %{mieee-fp:-lieee} %{pthread:-lpthread}    %{profile:-lc_p} %{!profile: -lc}}

*libgcc:
-lgcc

*startfile:
%{!shared:      %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s}                   %{!p:%{profile:gcrt1.o%s}                   %{!profile:crt1.o%s}}}}    crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}

*switches_need_spaces:


*signed_char:
%{funsigned-char:-D__CHAR_UNSIGNED__}

*predefines:
-D__ELF__ -Dunix -D__i386__ -Dlinux -Asystem(posix)

*cross_compile:
0

*version:
2.95.2

*multilib:
. ;

*multilib_defaults:


*multilib_extra:


*multilib_matches:


*linker:
collect2

*cpp_486:
%{!ansi:-Di486} -D__i486 -D__i486__

*cpp_586:
%{!ansi:-Di586 -Dpentium}       -D__i586 -D__i586__ -D__pentium -D__pentium__

*cpp_k6:
%{!ansi:-Di586 -Dk6}    -D__i586 -D__i586__ -D__k6 -D__k6__

*cpp_686:
%{!ansi:-Di686 -Dpentiumpro}    -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__

*cpp_cpu_default:
%(cpp_686)

*cpp_cpu:
-Acpu(i386) -Amachine(i386) %{!ansi:-Di386} -D__i386 -D__i386__ %{mcpu=i486:%(cpp_486)} %{m486:%(cpp_486)} %{mpentium:%(cpp_586)} %{mcpu=pentium:%(cpp_586)} %{mpentiumpro:%(cpp_686)} %{mcpu=pentiumpro:%(cpp_686)} %{mcpu=k6:%(cpp_k6)} %{!mcpu*:%{!m486:%{!mpentium*:%(cpp_cpu_default)}}}

*cc1_cpu:
%{!mcpu*: %{m386:-mcpu=i386 -march=i386} %{m486:-mcpu=i486 -march=i486} %{mpentium:-mcpu=pentium} %{mpentiumpro:-mcpu=pentiumpro}}

*link_command:
%{!fsyntax-only:  %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n}                  %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}                     %{!A:%{!nostdlib:%{!nostartfiles:%S}}}                    %{static:} %{L*} %D %o                  %{!nostdlib:%{!nodefaultlibs:%G %L %G}}                   %{!A:%{!nostdlib:%{!nostartfiles:%E}}}                    %{T*}
 }}}}}}

/tmp>gcc -dumpmachine
i686-pc-linux-gnu
/tmp>gcc -dumpversion
2.95.2
/tmp>uname -a
Linux iwsl011.iil.intel.com 2.2.12-20smp #2 SMP Mon Feb 14 05:41:40 PST 2000 i686 unknown

How-To-Repeat:
copy some file from /usr/lib to ~/:

Unformatted:
 >gcc -L $tools/sys/glib-1.2.7/lib --print-file-name=libglib.a
 /usr/lib/libglib.a
 >setenv LIBRARY_PATH $tools/sys/glib-1.2.7/lib
 >gcc -L $tools/sys/glib-1.2.7/lib --print-file-name=libglib.a
 /afs/iil/nike/data/tools/sys/glib-1.2.7/lib/libglib.a
 
 You see that I gave the same directory on command line
 and /usr/lib from builtin configuration did override it,
 while LIBRARY_PATH overrides both built-in and command line
 parameters!
 
 The documentation for gcc says:
 
 GCC info 7 says:
    Note that you can also specify places to search using options such as
 `-B', `-I' and `-L' (*note Directory Options::.).  These take
 precedence over places specified using environment variables, which in
 turn take precedence over those specified by the configuration of GCC.
 
 >cp /usr/lib/libglib.a ~/
 >gcc -L ~/ --print-file-name=libglib.a
 which is incorrect, because the file must be looked up
 in -L first!
Comment 1 Wolfgang Bangerth 2003-01-14 14:54:50 UTC
State-Changed-From-To: open->feedback
State-Changed-Why: Hi,
    there have been many changes in the area of path handling,
    in particular with the switch from static to shared 
    libraries, since 2.95. Do you know whether this old
    problem still applies with newer versions of gcc?
    
    Thanks
      Wolfgang
Comment 2 Wolfgang Bangerth 2003-04-16 23:19:39 UTC
State-Changed-From-To: feedback->closed
State-Changed-Why: No feedback