> Apparently folks are still having trouble with this.
> This should help.
> BUILDING AN A.OUT EXECUTABLE FROM HELLO.C ON FREEBSD 3
> Tested on FreeBSD 3.3-R
> Get the following files from /usr/lib on a FreeBSD 2.2 system and
> put them in the working directory:
> crt0.o
> libgcc.a
> % setenv OBJFORMAT aout
> % cc -c hello.c
> % /usr/libexec/aout/ld -e start -dc -dp -o hello crt0.o hello.o libgcc.a
> -L/usr/lib/compat/aout -lc libgcc.a
> NOTE 1: "cc -o" cannot be used because it uses /usr/lib/libgcc.a, which
> is elf rather than aout. Note also that "cc -o" looks for crt0.o
> in the current directory. You can see the link command that "cc -o"
> uses by adding the -v option.
you are wrong.
Quote:> NOTE 2: If you use additional cc options you may need other *crt*.o
> files. You may also need libgcc_p.a or libgcc_pic.a.
well.
Quote:> NOTE 3: If you are doing this a lot, put the link command in a
> shell script or something. Better yet, fix the gcc compiler
> driver and submit a PR with the fix.
see below.
Quote:> NOTE 4: I have an empty /usr/lib/aout directory on my system
> (after a binary install of 3.3-R). I suspect that's the
> "official" home of the 2.2 *crt*.o and libgcc*.a files.
serious things begins now :)
you are luky, I'm just looking how to make a.out file.
I need it to compile something...
first, you need the startup object files :
cd /usr/src/lib/csu/i386
make clean
OBJFORMAT=aout make
install -c -o root -g wheel -m 444 crt0.o c++rt0.o gcrt0.o scrt0.o sgcrt0.o /us
r/lib/aout
make clean
also, a libgcc in a.out format :
[ -d /usr/obj ] && mv /usr/obj /usr/obj-
cd /usr/src/gnu/usr.bin/cc/libgcc
make clean
OBJFORMAT=aout make
install -c -o root -g wheel -m 444 libgcc.a /usr/lib/aout
install -c -o root -g wheel -m 444 libgcc_pic.a /usr/lib/aout
make clean
[ -d /usr/obj- ] && mv /usr/obj- /usr/obj
never do a make install, this will override your elf objects and libraries :(
if you really need to modify the "specs" file :
gcc -dumpspecs > /usr/libdata/gcc/specs
gcc -dumpspecs > /usr/libdata/gcc/aout/specs
rm -f /usr/bin/gcc-aout
cat > /usr/bin/gcc-aout << 'EOF'
#!/bin/sh -x
LIBRARY_PATH=/usr/lib/compat/aout
export LIBRARY_PATH
if [ -n "$AOUT_LIBRARY_PATH" ]; then
LIBRARY_PATH=/usr/lib/compat/aout:${AOUT_LIBRARY_PATH}
fi
case " $*" in *" -v "*)
echo LIBRARY_PATH=$LIBRARY_PATH
;; esac
EOF
chmod +x /usr/bin/gcc-aout
you need the -B option to reach the specs file and the LIBRARY_PATH
to reach the a.out shared libraries. the COMPILER_PATH not seems to be
needed. you can use the AOUT_LIBRARY_PATH to complete the library
search path. so, this will not conflict with the LIBRARY_PATH reserved
for the elf use.
now, do whatever you want in the "specs" file in /usr/libdata/aout/specs
a simple test prog...
root# cd /tmp
root# cat > c.c << EOF
#include <math.h>
main () { printf ("hello world : %f\n", cos(M_PI)); return; }
EOF
in a.out format...
root# gcc-aout -v -o c c.c -lm
LIBRARY_PATH=/usr/lib/compat/aout
gcc -B/usr/libdata/gcc/aout/ -aout -v -o c c.c -lm
Reading specs from /usr/libdata/gcc/aout/specs
gcc version 2.7.2.3
/usr/libexec/cpp -lang-c -v -isystem /usr/libdata/gcc/aout/include -undef -D__G
NUC__=2 -D__GNUC_MINOR__=7 -Dunix -Di386 -D__FreeBSD__=3 -D__FreeBSD_cc_version=
330001 -D__unix__ -D__i386__ -D__FreeBSD__=3 -D__FreeBSD_cc_version=330001 -D__u
nix -D__i386 -Asystem(unix) -Asystem(FreeBSD) -Acpu(i386) -Amachine(i386) -D__UN
DERSCORES__ c.c /var/tmp/ccc37531.i
GNU CPP version 2.7.2.3 (i386 FreeBSD)
#include "..." search starts here:
#include <...> search starts here:
/usr/libdata/gcc/aout/include
/usr/include
End of search list.
/usr/libexec/cc1 /var/tmp/ccc37531.i -munderscores -quiet -dumpbase c.c -maout
-version -o /var/tmp/ccc37531.s
GNU C version 2.7.2.3 (i386 FreeBSD) compiled by GNU C version 2.7.2.1.
/usr/libexec/aout/as -v -o /var/tmp/ccc375311.o /var/tmp/ccc37531.s
GNU assembler version 1.92.3, FreeBSD $Revision: 1.6 $
/usr/libexec/aout/ld -e start -dc -dp -o c /usr/lib/aout/crt0.o -L/usr/libdata/
gcc/aout -L/usr/lib/compat/aout -L/usr/libdata/gcc/aout -L/usr/libdata/gcc -L/us
r/lib/aout /var/tmp/ccc375311.o -lm /usr/lib/aout/libgcc.a -lc /usr/lib/aout/lib
gcc.a
root# ./c
hello world : -1.000000
in elf format...
root# gcc -v -o c c.c -lm
Reading specs from /usr/libdata/gcc/specs
gcc version 2.7.2.3
/usr/libexec/cpp -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=7 -Dunix -Di38
6 -D__FreeBSD__=3 -D__FreeBSD_cc_version=330001 -D__unix__ -D__i386__ -D__FreeBS
D__=3 -D__FreeBSD_cc_version=330001 -D__unix -D__i386 -Asystem(unix) -Asystem(Fr
eeBSD) -Acpu(i386) -Amachine(i386) -D__ELF__ c.c /var/tmp/ccE37537.i
GNU CPP version 2.7.2.3 (i386 FreeBSD)
#include "..." search starts here:
#include <...> search starts here:
/usr/include
End of search list.
/usr/libexec/cc1 /var/tmp/ccE37537.i -quiet -dumpbase c.c -version -o /var/tmp/
ccE37537.s
GNU C version 2.7.2.3 (i386 FreeBSD) compiled by GNU C version 2.7.2.1.
/usr/libexec/elf/as -v -o /var/tmp/ccE375371.o /var/tmp/ccE37537.s
GNU assembler version 2.9.1 (i386-unknown-freebsdelf), using BFD version 2.9.1
/usr/libexec/elf/ld -m elf_i386 -dynamic-linker /usr/libexec/ld-elf.so.1 -o c /
usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/libdata/gcc /var/tmp/c
cE375371.o -lm /usr/lib/libgcc.a -lc /usr/lib/libgcc.a /usr/lib/crtend.o /usr/li
b/crtn.o
root# ./c
hello world : -1.000000
OUAOUHHH!
some usefull gcc options :
root# strings /usr/bin/gcc | grep -- ^-print
root# gcc -print-prog-name=ld
/usr/libexec/elf/ld
root# gcc-aout -print-prog-name=ld
/usr/libexec/aout/ld
root# gcc -print-multi-directory
elf
root# gcc-aout -print-multi-directory
aout
root# gcc -print-multi-lib
elf;
root# gcc-aout -print-multi-lib
elf;
root# gcc -print-libgcc-file-name
/usr/lib/libgcc.a
root# gcc-aout -print-libgcc-file-name
/usr/lib/aout/libgcc.a
root# gcc -print-file-name=specs
/usr/libdata/gcc/specs
root# gcc-aout -print-file-name=specs
/usr/libdata/gcc/aout/specs
root# gcc -print-search-dirs
install: /usr/libexec/(null)
programs: /usr/libexec/elf/:/usr/libexec/:/usr/bin/
libraries: /usr/libdata/gcc/:/usr/lib/
root# gcc-aout -print-search-dirs
install: /usr/libexec/(null)
programs: /usr/libdata/gcc/aout/:/usr/libexec/aout/:/usr/libexec/:/usr/bin/
libraries: /usr/libdata/gcc/aout/:/usr/lib/compat/aout/:/usr/libdata/gcc/:/usr/l
ib/
about the specs file, bcoz I'm using FreeBSD 3.3, I'm not able to
give you a good specs file for a.out building to put in your
/usr/libdata/aout. sorry :)
have fun and good luck!
Cyrille.
--