Installing C and C++ Compilers on pfSense

2026-09-05 pfsense freebsd c c++ development firewall

Installing C and C++ Compilers on pfSense

⚠ Warning: The instructions in this post are *NOT* supported by Netgate and may ruin your router. Do this at your own risk!

I wanted to do some C development on a pfSense machine. Their packaging system purposefully does not include compilers or many development tools.

Furthermore, this is not officially supported and Netgate says explicitly not to do this:

https://docs.netgate.com/pfsense/en/latest/development/compile-software.html

Netgate’s official guidance is to install a FreeBSD VM matching the FreeBSD version on which your pfSense release is based and do your development there. This is sensible advice and in all honesty, I recommend you do this too. However, a situation arose where installing the appropriate FreeBSD VM wasn’t practical for me. These instructions came through for me in a pinch.

I referred to this documentation and uname to determine which FreeBSD release to download: https://docs.netgate.com/pfsense/en/latest/releases/versions.html

Instructions

Determine your FreeBSD version and architecture

uname and the administration web page confirm that I am using pfSense 2.6.0-RELEASE (FreeBSD 12.3-STABLE):

uname -v
FreeBSD 12.3-STABLE RELENG_2_6_0-n226742-1285d6d205f pfSense

I am using an amd64 processor:

uname -m
amd64

Download and extract the files from base.txz

Make a directory to work with, then download base.txz. The .txz file is about 180 MB. Unpacked, it is about 1 GB. Please ensure you have enough space before continuing.

You will need to adjust the URL if your target machine uses a different version of FreeBSD or architecture than what I am using:

mkdir -p /tmp/fbsd123/root
cd /tmp/fbsd123
fetch https://archive.freebsd.org/old-releases/amd64/amd64/12.3-RELEASE/base.txz
tar -xJf base.txz -C root

Copy necessary files to disk

Rather than replacing the entire pfSense base system, I selectively copy the compiler, linker, and headers from the corresponding FreeBSD release:

cp root/usr/bin/cc /usr/bin/cc
cp root/usr/bin/c++ /usr/bin/c++
cp root/usr/bin/clang /usr/bin/clang
cp root/usr/bin/clang++ /usr/bin/clang++
cp root/usr/bin/ld /usr/bin/ld
cp -Rp root/usr/include/* /usr/include/

Confirm it works

Confirm this worked by compiling a couple of small programs:

cat >/tmp/test.c <<EOF
#include <stdio.h>

int main(void)
{
    printf("C compiler and linker success!\n");
    return 0;
}
EOF

cc /tmp/test.c -o /tmp/test
/tmp/test

printf '%s\n' \
'#include <iostream>' \
'' \
'int main()' \
'{' \
'    std::cout << "C++ compiler and linker success!" << std::endl;' \
'    return 0;' \
'}' > /tmp/test.cc

c++ /tmp/test.cc -o /tmp/test
/tmp/test
rm /tmp/test /tmp/test.c /tmp/test.cc

If everything went according to plan, you should see this output:

C compiler and linker success!
C++ compiler and linker success!

Congratulations! You can now compile simple C and C++ programs on pfSense. Installing any additional libraries, headers, or development tools is left as an exercise to the reader.


No notes link to this note