# 32bit libgcc on FreeBSD 11.0



## freebsduser2282 (May 23, 2017)

Please let me know how to install 32bit libgcc and libstdc++ on FreeBSD 11.0
Steps showing actual issue is given below


```
[xyz]$ cat hello_world.c
#include<stdio.h>
int main(void)
{

printf("\n Hello World \n");
return 1;

}

[xyz]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc5/gcc/x86_64-portbld-freebsd11.0/5.4.0/lto-wrapper
Target: x86_64-portbld-freebsd11.0
Configured with: /wrkdirs/usr/ports/lang/gcc/work/gcc-5.4.0/configure --disable-bootstrap --disable-nls --enable-gnu-indirect-function --libdir=/usr/local/lib/gcc5 --libexecdir=/usr/local/libexec/gcc5 --program-suffix=5 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc5/include/c++/ --with-ld=/usr/local/bin/ld --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --with-ecj-jar=/usr/local/share/java/ecj-4.5.jar --enable-languages=c,c++,objc,fortran,java --prefix=/usr/local --localstatedir=/var --mandir=/usr/local/man --infodir=/usr/local/info/gcc5 --build=x86_64-portbld-freebsd11.0
Thread model: posix
gcc version 5.4.0 (FreeBSD Ports Collection)


[xyz]$ which gcc
/usr/local/bin/gcc

[xyz]$ gcc -m32 -O2 hello_world.c
/usr/local/bin/ld: skipping incompatible /usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd11.0/5.4.0/libgcc.a when searching for -lgcc
/usr/local/bin/ld: skipping incompatible //usr/lib/libgcc.a when searching for -lgcc
/usr/local/bin/ld: cannot find -lgcc
/usr/local/bin/ld: skipping incompatible /usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd11.0/5.4.0/../../../libgcc_s.so when searching for -lgcc_s
/usr/local/bin/ld: skipping incompatible //usr/lib/libgcc_s.so when searching for -lgcc_s
/usr/local/bin/ld: cannot find -lgcc_s
/usr/local/bin/ld: skipping incompatible /lib/libc.so.7 when searching for /lib/libc.so.7
/usr/local/bin/ld: cannot find /lib/libc.so.7
/usr/local/bin/ld: skipping incompatible /usr/lib/libc_nonshared.a when searching for /usr/lib/libc_nonshared.a
/usr/local/bin/ld: cannot find /usr/lib/libc_nonshared.a
/usr/local/bin/ld: skipping incompatible /usr/lib/libssp_nonshared.a when searching for /usr/lib/libssp_nonshared.a
/usr/local/bin/ld: cannot find /usr/lib/libssp_nonshared.a
collect2: error: ld returned 1 exit status


uname -a
FreeBSD 11.0-RELEASE-p1 FreeBSD 11.0-RELEASE-p1 #0 r306420: Thu Sep 29                                                                                                              01:43:23 UTC 2016     [email]root@releng2.nyi.freebsd.org[/email]:/usr/obj/usr/src/sys/GENERIC                                                                                                               amd64
```


----------



## freebsduser2282 (May 23, 2017)

Error with g++ and -m32 on FreeBSD 11.0

```
g++ -m32 -O2 hello_world.cpp
/usr/local/bin/ld: skipping incompatible /usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd11.0/5.4.0/../../../libstdc++.so when searching for -lstdc++
/usr/local/bin/ld: skipping incompatible /usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd11.0/5.4.0/../../../libstdc++.a when searching for -lstdc++
/usr/local/bin/ld: cannot find -lstdc++
/usr/local/bin/ld: skipping incompatible //usr/lib/libm.so when searching for -lm
/usr/local/bin/ld: skipping incompatible //usr/lib/libm.a when searching for -lm
/usr/local/bin/ld: cannot find -lm
/usr/local/bin/ld: skipping incompatible /usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd11.0/5.4.0/../../../libgcc_s.so when searching for -lgcc_s
/usr/local/bin/ld: skipping incompatible //usr/lib/libgcc_s.so when searching for -lgcc_s
/usr/local/bin/ld: cannot find -lgcc_s
/usr/local/bin/ld: skipping incompatible /usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd11.0/5.4.0/libgcc.a when searching for -lgcc
/usr/local/bin/ld: skipping incompatible //usr/lib/libgcc.a when searching for -lgcc
/usr/local/bin/ld: cannot find -lgcc
/usr/local/bin/ld: skipping incompatible /lib/libc.so.7 when searching for /lib/libc.so.7
/usr/local/bin/ld: cannot find /lib/libc.so.7
/usr/local/bin/ld: skipping incompatible /usr/lib/libc_nonshared.a when searching for /usr/lib/libc_nonshared.a
/usr/local/bin/ld: cannot find /usr/lib/libc_nonshared.a
/usr/local/bin/ld: skipping incompatible /usr/lib/libssp_nonshared.a when searching for /usr/lib/libssp_nonshared.a
/usr/local/bin/ld: cannot find /usr/lib/libssp_nonshared.a
collect2: error: ld returned 1 exit status
```


----------



## freebsduser2282 (May 23, 2017)

For gcc -m32 got solution from below link:
Source: https://lists.freebsd.org/pipermail/freebsd-stable/2011-March/061847.html

```
$ cat hello.c
#include<stdio.h>
int main(void)
{

printf ("\n Hello world \n");

}

$ gcc hello.c -m32 -B/usr/lib32

$ ./a.out 
Hello world
```


----------



## freebsduser2282 (May 23, 2017)

But , g++ with -m32 needs 32bit libstdc++.so , please let me know how to install this library on on FreeBSD 11.0
Using -B/usr/lib32 does not work with g++

```
$ g++ hello_world.cpp -m32 -B/usr/lib32
/usr/local/bin/ld: skipping incompatible /usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd11.0/5.4.0/../../../libstdc++.so when searching for -lstdc++
/usr/local/bin/ld: skipping incompatible /usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd11.0/5.4.0/../../../libstdc++.a when searching for -lstdc++
/usr/local/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
```


----------

