# Upgrade gcc4.2 to gcc4.8



## Naos (Aug 26, 2013)

Hi,

I need to upgrade gcc to compile a dynamic library in *C*++. I've already installed gcc48 but typing `gcc --v` it says I'm still using gcc42, so I've solved typing gcc48 directly but:

```
g incompatible /usr/local/lib/gcc48/gcc/x86_64-portbld-freebsd9.1/4.8.1/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/gcc48/gcc/x86_64-portbld-freebsd9.1/4.8.1/../../../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/lib/libc.so when searching for -lc
/usr/local/bin/ld: skipping incompatible //usr/lib/libc.a when searching for -lc
/usr/local/bin/ld: cannot find -lc
/usr/local/bin/ld: skipping incompatible /usr/local/lib/gcc48/gcc/x86_64-portbld-freebsd9.1/4.8.1/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/gcc48/gcc/x86_64-portbld-freebsd9.1/4.8.1/../../../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
collect2: error: ld returned 1 exit status
```

How do I fix this? :\


----------



## ondra_knezour (Aug 26, 2013)

Using newer version of GCC and binutils with the FreeBSD Ports Collection


----------



## Naos (Aug 26, 2013)

ondra_knezour said:
			
		

> Using newer version of GCC and binutils with the FreeBSD Ports Collection


How do you think I've installed gcc48? It doesn't work though*.*


----------



## vand777 (Aug 28, 2013)

I'll share my experience with gcc48.

I'm not using it to compile ports or kernel/world because it is not officially supported and I'm not looking for trouble. However, at my company we develop cross-platform applications for Windows/Linux/Unix and we use FreeBSD 9.1 as our Unix testing platform.

These applications/libraries are all contain C++11 features, so we need to use the latest compilers which support C++11. We use GCC 4.8.

What I changed on my system:

 Installed GCC 4.8 from ports.
 Installed the latest devel/gdb from ports (the one in the base does not support new language features) 
 Added the following lines to /etc/profile:

```
export LD_LIBRARY_PATH=/usr/local/lib/gcc48:${LD_LIBRARY_PATH}
export CC=/usr/local/bin/gcc48
export CXX=/usr/local/bin/g++48
alias make="gmake"
alias gdb="/usr/local/bin/gdb76"
alias g++="g++48"
```

 Added the following line to ~/.bashrc (if you using other shell than bash, then you need to do it as described for your shell):

```
source /etc/profile
```

 Log off and log in.
Now when I log in as my user, gcc and g++ are aliases of gcc48 and g++48 respectively. New C++11 libraries from /usr/local/lib/gcc48 are being used by linker. We use gmake instead of make, that's why I have an alias for make.

I also managed to install Eclipse Juno and the CDT plugin on FreeBSD which is also very helpful.


----------



## kpa (Aug 28, 2013)

You have to adjust /etc/libmap.conf to get the C++ stuff to link properly. The libgcc.so library that comes with the base system is only for code that is compiled with the built-in gcc/g++ version 4.2.1.


----------



## vand777 (Aug 28, 2013)

kpa said:
			
		

> You have to adjust /etc/libmap.conf to get the C++ stuff to link properly. The libgcc.so library that comes with the base system is only for code that is compiled with the built-in gcc/g++ version 4.2.1.



I haven't applied any changes to this file and it still links correctly on my machine. Maybe because of the below line?

```
export LD_LIBRARY_PATH=/usr/local/lib/gcc48:${LD_LIBRARY_PATH}
```


----------

