🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #155

Cross compiling hints, given and wanted

#155
From: Brian L. Kahn
Date: Thu, 16 Apr 1992 21:25
90 lines
4753 bytes

I've been struggling for weeks to get a cross compiler generated by
gcc-2.1, and I've finally done it.  Sort of.  I can compile simple
programs, but compiles of Xwindows code dies.  Here are hints for as
far as I've gone - if anyone can help me with cross compiling X that
would be much appreciated.

There seems to be two groups on the net familiar with building a gcc
cross compiler: 1) people who built the cross compiler so easily that
they can't understand why anyone would have trouble, and 2) people who
are floundering about like I was.  I didn't get much help from the
net, which is unusual; I think that the method must be entirely
obvious to those that have succeeded.  There seems to be a small but
continuing stream of questions about cross compiling so I think this
is worth posting.


I need a cross compiler for suns, target sun3 and host sun4.  We have
a few sun3's left, but they are being phased out and I don't want to
pay maintenance just to compile the occasional sun3 binary.  This
should be the easiest possible case for a gcc cross compiler, the
example that is in fact used when describing CONFIGURE.  Nonetheless,
I find the directions very confusing.

Here is the procedure that finally worked for me.  Some of this may
not be necessary, but I think this has a pretty good shot at working
even for differing host and target.

1) Configure and build native gcc for the host, make realclean
2) Build and install gnu ar, ranlib, make (may not be required)
3) Build gas and gnu ld-1.94beta as a cross-assembler and cross-linker
 host>  cd /usr/gnu/ld-1.94beta/ld
 host>  ../configure --host=sun4 --target=sun3 ; make CC=gcc
 host>  cd /usr/gnu/gas
 host>  ln -s m-sun3.h m68k.h ; make a68
4) Make target directories, install (2) and (3) in /prefix/target/bin
 host>  cd /usr/local ; mkdir sun3 sun3/bin
 host>  cd /usr/local/lib/gcc-lib ; mkdir sun3 sun3/2.1
 host>  ln -s /usr/gnu/bin/{ar,ranlib} /usr/local/sun3/bin
 host>  cp /usr/gnu/gas/a68 /usr/local/sun3/bin/as
 host>  cp /usr/gnu/binutils-beta-1.94/ld/ld.new /usr/local/sun3/bin/ld
5) Copy libraries and includes from the target
 host>  cd /usr/local/sun3
 host>  rsh target 'cd /usr ; tar cf - lib/*{.a,.o,.sa.*,.so.*}' | tar xf -
 host>  rsh target 'cd /usr ; tar cf - include | tar xf -
 host>  cd include ; rm machine ; ln -s sun3 machine
6) Link (5) to gnu library directory
 host>  cd /usr/local/lib/gcc-lib/sun3/2.1
 host>  ln -s /usr/local/sun3/lib/* /usr/local/sun3/bin/* .
 host>  ln -s /usr/local/sun3/include sys-include
7) Build gcc cross compiler
 host>  cd /usr/gnu/gcc-2.1
 host>  configure --host=sun4 --target=sun3
 host>  make CC=gcc LANGUAGES=c
8) Install the cross compiler
 host>  make CC=gcc LANGUAGES=c install-cross 
9) Fix the SUN include files, using the target includes
 host>  make CC=gcc INPUT=/usr/local/sun3/include install-fixincludes


Here is my problem: I can't link X11 programs, even tho I have copied
the X11 include and lib files from a running target.  When I try to
compile xabacus, for example, the objects are created OK but I can't
link them.

sparc>  gcc-sun3 -o xabacus main.o Xinit.o aba.o demo.o -g -D_NO_PROTO -DSTRINGS_ALIGNED -DNO_REGEX -DNO_ISDIR -DUSE_RE_COMP -DUSE_GETWD -lXext -lX11 -lXt   
Initialize.o: undefined reference to `_XResourceManagerString'
Initialize.o: undefined reference to `_XrmParseCommand'
Intrinsic.o: undefined reference to `_XMapSubwindows'
Intrinsic.o: undefined reference to `_XDestroyWindow'
...goes on and on....

If I ship them over to my target (a sun3 with gnu tools) I can link
them with gnu ld.  Using gnu ld compiled for a sun3 target on my
sparc, I get the same errors as with gcc-sun3.

sparc>  /usr/local/sun3/bin/ld -o xabacus main.o Xinit.o aba.o demo.o -L/usr/local/lib/gcc-lib/sun3/2.1 -lXext -lX11 -lXt -lgcc -lc
Initialize.o: undefined reference to `_XResourceManagerString'
Initialize.o: undefined reference to `_XrmParseCommand'
Intrinsic.o: undefined reference to `_XMapSubwindows'
Intrinsic.o: undefined reference to `_XDestroyWindow'
Intrinsic.o: undefined reference to `_XCreateWindow'



I hope these hints help.  Any suggestions?

--
B<   Brian Kahn   blk@security.mitre.org   "may the farce be with you"
Technical Details
Message-ID: <BLK.92Apr16162557@vanity.mitre.org>
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!linus!linus.mitre.org!news!mbunix!blk

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!linus!linus.mitre.org!news!mbunix!blk
From: blk@mitre.org (Brian L. Kahn)
Newsgroups: gnu.gcc.help
Subject: Cross compiling hints, given and wanted
Message-ID: <BLK.92Apr16162557@vanity.mitre.org>
Date: 16 Apr 92 21:25:57 GMT
Article-I.D.: vanity.BLK.92Apr16162557
Sender: news@linus.mitre.org (News Service)
Distribution: gnu
Organization: The MITRE Corp. Bedford, MA
Lines: 90
Nntp-Posting-Host: vanity.mitre.org