# compiling kernel with new GCC version



## SIFE (Jun 1, 2010)

i had just installed gcc46 ,now i am trying to compile my kernel with this version for hack  ,i added in bsd.own.mk this :

```
LIBDIR?=        /usr/lib \
                /usr/local/lib
INCLUDEDIR?=    /usr/include \
                /usr/local/include
```
the error i get from buildkernel :

```
cd /usr/obj/usr/src/sys/STABLE;  MAKESRCPATH=/usr/src/sys/dev/aic7xxx/aicasm  make SSP_CFLAGS= -DNO_CPU_CFLAGS -DNO_CTF  -f /usr/src
/sys/dev/aic7xxx/aicasm/Makefile
Warning: Object directory not changed from original /usr/obj/usr/src/sys/STABLE
gcc46 -pipe -nostdinc -I/usr/include -I. -I/usr/src/sys/dev/aic7xxx/aicasm -std=gnu99  -Wsystem-headers -Werror -Wall -Wno-format-y2k -W 
-Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow 
-Wcast-align -Wunused-parameter -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -Wno-pointer-sign -c /usr/src/sys/dev/aic7xxx
/aicasm/aicasm.c
gcc46: not found
*** Error code 127

Stop in /usr/obj/usr/src/sys/STABLE.
*** Error code 1

Stop in /usr/src.
*** Error code 1

Stop in /usr/src.
```


----------



## vrachil (Jun 1, 2010)

have you checked this guide?
http://www.freebsd.org/doc/en/articles/custom-gcc/article.html


----------



## SIFE (Jun 1, 2010)

that is for ports not for kernel or build world .


----------



## Erratus (Jun 1, 2010)

That guide says that newer versions of GCC can be used but stays short of usage for building world and kernel. 
I remember that this is still not possible. Tell me if I'm wrong about that.


----------



## DutchDaemon (Jun 1, 2010)

FreeBSD's base system is a coherent whole, which needs to be built with its base system compilers, not external ones.


----------



## Erratus (Jun 1, 2010)

DutchDaemon said:
			
		

> FreeBSD's base system is a coherent whole, which needs to be built with its base system compilers, not external ones.


Anything in the pipeline to change/update the base system compiler in near future?


----------



## vrachil (Jun 1, 2010)

SIFE said:
			
		

> that is for ports not for kernel or build world .


Oops. You are right. My bad. 



			
				Erratus said:
			
		

> Anything in the pipeline to change/update the base system compiler in near future?


There are efforts to use clang for building world, but as reported on the mailing lists, it needs more testing.


----------



## Erratus (Jun 1, 2010)

For those who want to test have a look on the wiki Building FreeBSD with clang/llvm


----------



## SIFE (Jun 1, 2010)

are you trying Mr DutchDaemon  to say that is impossible to compile kernel with extranal compiler ,and where about this file "share/mk/sys.mk" .


----------



## DutchDaemon (Jun 1, 2010)

Not impossible, it may work (as in: successfully compile). And then there's the inevitable forum post to which the answer is: "Any compiler flags in /etc/make.conf? Remove them and try again". The fact that FreeBSD allows you to use flags and external compilers doesn't mean they will actually work. The default compilers and flags will _always_ work.


----------



## phoenix (Jun 1, 2010)

Erratus said:
			
		

> Anything in the pipeline to change/update the base system compiler in near future?



Clang is being imported into the FreeBSD source tree this month.  GCC 4.2.1 will remain in the source tree, and will remain the default compiler.  However, there will be knobs you can set in /etc/make.conf and/or /etc/src.conf to use Clang to compile the world/kernel.


----------



## SIFE (Jun 1, 2010)

any suggestion to make this hack work ,i tryed to make some change in make.conf but this does not work .


----------



## phoenix (Jun 2, 2010)

SIFE said:
			
		

> are you trying Mr DutchDaemon  to say that is impossible to compile kernel with extranal compiler ,and where about this file "share/mk/sys.mk" .



There's work in the pipeline to allow for the use of external compiler toolchains to build the world/kernel/ports.  It's not ready for public testing, but work is ongoing.

For some information, see the wiki.


----------



## trasz@ (Jan 17, 2011)

Just for the record - I've successfully compiled kernel (9.0-CURRENT, about six months ago) with GCC 4.5 with this in /etc/make.conf:


```
CC= /usr/local/bin/gcc45
CXX= /usr/local/bin/g++45
CWARNFLAGS= -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \
-Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual \
-Wno-pointer-sign -D__FreeBSD_cc_version=0 \
-Wno-unused-function -Wno-inline -Wno-format \
-Wno-uninitialized -Wno-array-bounds -Wno-missing-prototypes
NO_WERROR= 1
```


----------



## SirDice (Jan 17, 2011)

So it compiles fine, but does it also _run_? Stable?


----------



## trasz@ (Jan 17, 2011)

Yes, it ran fine on amd64.


----------



## DutchDaemon (Jan 17, 2011)

I repeat: http://forums.freebsd.org/showpost.php?p=119582&postcount=16


----------

