# Compiling the kernel via GCC



## Pegasus711 (Aug 27, 2017)

Has anyone been able to successfully compile the kernel using GCC as against CLANG the default compiler on most later versions of FreeBSD? I was able to successfully buildworld. After which I reboot and now /usr/bin/cc points to GCC as requested. However kernel fails to link
Here is my src.conf:

`COPTFLAGS+= -O0 -pipe -Wno-attributes -Wno-redundant-decls
WERROR="-Wno-error"
WITHOUT_CLANG="yes"
WITHOUT_CLANG_IS_CC="yes"
WITHOUT_CLANG_BOOTSTRAP="yes"
WITH_GCC_BOOTSTRAP="yes"
WITH_GCC="yes"
WITH_GNUCXX="yes"
WITHOUT_JAIL="yes"
WITHOUT_WIRELESS="yes"
WITHOUT_WIRELESS_SUPPORT="yes"
WITHOUT_WPA_SUPPLICANT_EAPOL="yes"
WITHOUT_CDDL="yes"`

It fails here:

```
>>> stage 3.1: building everything
--------------------------------------------------------------
cd /usr/obj/usr/src/sys/AIJAZ-DEBUG; COMPILER_VERSION=40201 COMPILER_FEATURES= COMPILER_TYPE=gcc COMPILER_FREEBSD_VERSION=1200001 MAKEOBJDIRPREFIX=/usr/obj MACHINE_ARCH=amd64 MACHINE=amd64 CPUTYPE= CC="cc -isystem /usr/obj/usr/src/tmp/usr/include -L/usr/obj/usr/src/tmp/usr/lib -B/usr/obj/usr/src/tmp/usr/lib --sysroot=/usr/obj/usr/src/tmp -B/usr/obj/usr/src/tmp/usr/bin" CXX="c++  -isystem /usr/obj/usr/src/tmp/usr/include -L/usr/obj/usr/src/tmp/usr/lib -B/usr/obj/usr/src/tmp/usr/lib --sysroot=/usr/obj/usr/src/tmp -B/usr/obj/usr/src/tmp/usr/bin" CPP="cpp -isystem /usr/obj/usr/src/tmp/usr/include -L/usr/obj/usr/src/tmp/usr/lib -B/usr/obj/usr/src/tmp/usr/lib --sysroot=/usr/obj/usr/src/tmp -B/usr/obj/usr/src/tmp/usr/bin" AS="as" AR="ar" LD="ld" LLVM_LINK="" NM=nm OBJCOPY="objcopy" RANLIB=ranlib STRINGS= SIZE="size" INSTALL="sh /usr/src/tools/install.sh" PATH=/usr/obj/usr/src/tmp/legacy/usr/sbin:/usr/obj/usr/src/tmp/legacy/usr/bin:/usr/obj/usr/src/tmp/legacy/bin:/usr/obj/usr/src/tmp/usr/sbin:/usr/obj/usr/src/tmp/usr/bin:/sbin:/bin:/usr/sbin:/usr/bin make  -D KERNFAST -m /usr/src/share/mk  KERNEL=kernel all -DNO_MODULES_OBJ
linking kernel.full
ck_array.o: In function `ck_cc_popcount':
/usr/src/sys/contrib/ck/include/gcc/ck_cc.h:139: undefined reference to `__popcountdi2'
ck_barrier_centralized.o: In function `ck_cc_popcount':
/usr/src/sys/contrib/ck/include/gcc/ck_cc.h:139: undefined reference to `__popcountdi2'
ck_barrier_combining.o: In function `ck_cc_popcount':
/usr/src/sys/contrib/ck/include/gcc/ck_cc.h:139: undefined reference to `__popcountdi2'
ck_barrier_dissemination.o: In function `ck_cc_popcount':
/usr/src/sys/contrib/ck/include/gcc/ck_cc.h:139: undefined reference to `__popcountdi2'
ck_barrier_mcs.o: In function `ck_cc_popcount':
/usr/src/sys/contrib/ck/include/gcc/ck_cc.h:139: undefined reference to `__popcountdi2'
ck_barrier_tournament.o:/usr/src/sys/contrib/ck/include/gcc/ck_cc.h:139: more undefined references to `__popcountdi2' follow
*** Error code 1

Stop.
make[2]: stopped in /usr/obj/usr/src/sys/AIJAZ-DEBUG
*** Error code 1

Stop.
make[1]: stopped in /usr/src
*** Error code 1

Stop.
make: stopped in /usr/src
```
That symbol seems to be not defined in one of the sources but I think this symbol might be getting generated on the fly via some #pragma or similar 'magic' but not too sure. 
Is there something else I am missing? Need some help


----------

