Subject: Bulding my own static libraries?
To: Alexander Klein <Alexander.Klein@math.uni-giessen.de>
From: Bruce O'Neel <bruce.oneel@obs.unige.ch>
List: port-mac68k
Date: 04/01/2002 10:50:47
Hi,

Um, I don't know what the problem might be but:

- BSDish systems really really like ranlib, though the s option to ar
should have done that for your.

- lorder might help.  From the lorder man page:

ar cr library.a `lorder ${OBJS} | tsort`


I did the following and it worked:

[beoneel@wabisabi68k 75]$ cc -c -m68040 t1.c                 
[beoneel@wabisabi68k 76]$ ar rvs libstuff.a t1.o             
a - t1.o
[beoneel@wabisabi68k 77]$ cc -m68040 -o t t.c             
/tmp/ccYUsTO0.o: Undefined symbol `_t1' referenced from text segment
collect2: ld returned 1 exit status
[beoneel@wabisabi68k 78]$ cc -m68040 -o t t.c -L. -lstuff 
[beoneel@wabisabi68k 79]$ ./t
in t1 10
23
[beoneel@wabisabi68k 80]$ 

where t.c is:

#include <stdio.h>

int t1(int b);

int main (int argc, char **argv)
{
  printf ("%d\n",t1(10));
  
}


and t1.c is:


int t1(int b)
{
        printf("in t1 %d\n",b);
        return 3+b*2;
}

[beoneel@wabisabi68k 82]$ uname -a
NetBSD wabisabi68k 1.5 NetBSD 1.5 (GENERICSBC) #0: Sun Nov 19 14:25:41 PST 2000     root2@c610:/usr/cvs/src/sys/arch/mac68k/compile/GENERICSBC mac68k
[beoneel@wabisabi68k 83]$ gcc -v
Using builtin specs.
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)

Though all of the rest of the system is from 1.5.2.

cheers

bruce

Alexander Klein writes:
 > Hi,
 > 
 > I know this is maybe the wrong place for this question, but I've looked in
 > all the standard places and found no satisfactory answer to my question:
 > 
 > Does anyone know how I have to build static libraries for use with gcc?
 > 
 > According to all the descriptions I found, it should be sufficient to:
 > 
 > gcc -c -m68040 stuff.c
 > ar rsv libstuff.a stuff.o
 > 
 > and then tell gcc where to find libstuff.a with -L along with a '-lstuff'
 > option.
 > 
 > In fact, it works to this point, libstuff.a is found by gcc, nm -s
 > libstuff.a shows that all the objects are in the table of contents, but the
 > linker (ld) always dies with something like 'Undefined object _blabla
 > referenced from text segment', although nm lists _blabla as a name in
 > libstuff.a
 > 
 > What could I do wrong?
 > 
 > Best regards, and happy easter to all!
 > 
 > 	Alex
 > 
 > 

-- 
Of course it runs NetBSD

Bruce O'Neel                       phone:  +41 22 950 91 57
INTEGRAL Science Data Centre               +41 22 950 91 00 (switchb.)
Chemin d'Ecogia 16                 fax:    +41 22 950 91 35
CH-1290 VERSOIX                    e-mail: Bruce.Oneel@obs.unige.ch
Switzerland                        WWW:    http://isdc.unige.ch/