Viewable by the world

Sample Code and Simple Compiles

Test Program

$ cat >bittest.c <<EOF
#include <stdio.h>
int main(){
    long z; printf("Long int size is %i bytes long!\n", sizeof(z)); return 0;
}
EOF

64 bit works of course

$ uname -m
amd64
$ gcc -o bittest bittest.c
$ ./bittest
Long int size is 8 bytes long!

32 bit doesn't work because gcc doesn't look under /usr/lib32

$ gcc -m32 -o bittest bittest.c
/usr/bin/ld: skipping incompatible /usr/lib/libgcc.a when searching for -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc

If we link the binary ourselves explicitly against /usr/lib32, it works

$ gcc -c -m32 -o bittest32.o bittest.c

$ /usr/bin/ld --eh-frame-hdr -m elf_i386_fbsd -V -dynamic-linker          \
  /libexec/ld-elf32.so.1 -o bittest32 /usr/lib32/crt1.o                   \
  /usr/lib32/crti.o /usr/lib32/crtbegin.o -L/usr/lib32 bittest32.o -lgcc  \
  --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s        \
  --no-as-needed /usr/lib32/crtend.o /usr/lib32/crtn.o
GNU ld version 2.15 [FreeBSD] 2004-05-23
  Supported emulations:
   elf_i386_fbsd
   elf_x86_64_fbsd
$ ./bittest32
Long int size is 4 bytes long!
  • No labels

2 Comments

  1. Unknown User ([email protected])

    Does this also happen in the latest release or the stable tree?

    1. I don't think this is a bug that will change under different updates. This is on a FreeBSD 7.2-RELEASE-p4 system. It just has to do with the fact that 32-bit libraries go under /usr/lib32 in a 64-bit system with compatibility libraries installed. There is probably an easier way to link against it if you are BUILDING a 32-bit binary under 64-bit, I just haven't played with it too much yet.