I have the following problem: I want to be able to compile and statically
link source code against standard libraries (libc6 and friends) which are
different version than the ones installed on the system. I have the second
set of libraries installed in non-default location.
I do not seem to be able to force gcc/ld to do that. Any help or pointer
would be appreciated.
gcc-3.3 --version
gcc-3.3 (GCC) 3.3 (Debian)
Copyright (C) 2003 Free Software Foundation, Inc.
ld --version
GNU ld version 2.13.90.0.18 20030121 Debian GNU/Linux
Copyright 2002 Free Software Foundation, Inc.
Thanks,
Tomas
--------------------------------------------------------------------------
Tomas Vinar, University of Waterloo graduate student
E-mail: tvi...@math.uwaterloo.ca
Office: DC3542, (519)888-4567 ext. 3564
Home phone: (519)746-7632
Plain old -static doesn't work?
--
Stefanus Du Toit; http://3.141592.org/; gpg 4bf2e217; #include <iostream>
template<int i,int j=i-1>struct I{I(){if(i%j)I<i,j-1>();else I<i-1>();}};
template<int i>struct I<i,1>{I(){std::cout<<i<<'\n';I<i-1>();}};template<
>struct I<1,0>{I(){}};int main(){I<50>();}/* Use -ftemplate-depth-5000 */
> I want to be able to compile and statically
> link source code against standard libraries (libc6 and friends) which are
> different version than the ones installed on the system. I have the second
> set of libraries installed in non-default location.
Perhaps you're looking for the -L option? Give it to gcc, and it will
get passed to ld.
-Lsearchdir
--library-path=searchdir
Add path searchdir to the list of paths that ld will search for
archive libraries and ld control scripts. You may use this option
any number of times. The directories are searched in the order in
which they are specified on the command line. Directories speci-
fied on the command line are searched before the default directo-
ries. [...]
gdm
This is the first thing I have tried; however, it still takes libc6 from
default system location... :-( Neither did help various combinations
of -nostdlibs and friends (for example, nostdlibs ignored all the standard
libraries EXCEPT libc6, which it took from the standard location).
My problem is that I need to add my directory into searchdir path AND at
the same time to remove standard directories (/lib) from it.
Tomas
You probably want to do something like this:
gcc -static -nostdlib -Lmydir -lgcc -lc mycrtn.o myobjs.o -o myprog
"-nostdlib" prevents use of the standard libs AND the startup code, so
you need to provide your own crtn.o, and -l options for every lib the
program needs. If you don't care about the startup code part, you can
try "-nodefaultlibs" option instead.
A comparable option you might be interested in is the "-nostdinc"
option, which prevents automatic inclusion of the standard include
paths (ie, so you can use the headers for the libc you're compiling
for):
gcc -nostdinc -Imyincludes myfoo.c -o myfoo.o
Hope that points you in the right direction!
-
I think that almost works, except perhaps that
a) you need to specify the -l options after the .o's
b) gcc/ld may still search the system library paths before it searches
paths you supply with -L
If b) gives you trouble, specify /path/to/my/libc.a instead of -lc.
As well, there's the possibility that you need to use the new dynamic
linker instead of the old; you can specify this with (from memory)
-Wl,-dynamic-linker=/path/to/my/ld-linux.so
You might think that using -static would make that unnecessary, but I
wouldn't bet on it.
- Richard
(who has tried the above, with varying degrees of failure)