21.1 C/C++ Development Environment
C/C++ Overview
C and C++ are widely used in systems programming, high-performance computing, embedded development, and other fields.
The FreeBSD kernel and a large number of userland utilities are written in C.
LLVM / Clang Overview
The FreeBSD base system includes the Clang compiler, but does not include other LLVM components such as clangd (a language server for code completion, compilation error diagnostics, and go-to-definition), Clang-Tidy (a code style diagnostic tool), and clang-format (for formatting C/C++ code).
To install LLVM, any version of LLVM may be used, but the version should not be lower than the system's built-in Clang.
Check the Clang compiler version in FreeBSD 16:
$ clang -v
FreeBSD clang version 21.1.8 (https://github.com/llvm/llvm-project.git llvmorg-21.1.8-0-g2078da43e25a)
Target: x86_64-unknown-freebsd16.0
Thread model: posix
InstalledDir: /usr/bin
Build config: +assertionsThe following uses LLVM 22 (the version at the time of writing). After installation, the corresponding programs are named clang22, clang++22, clangd22, and clang-format22. The system's built-in Clang program is named clang. If using a different version, note the corresponding program names.
LLVM Version Numbers in the LLVM Project Upstream
In the LLVM project upstream source code, the version number for LLVM 19 was defined by the file llvm/CMakeLists.txt. After this commit, the version number is instead defined by the source file cmake/Modules/LLVMVersion.cmake.
LLVM Version Numbers in the FreeBSD Base System
FreeBSD imports LLVM into the base system source code, but not directly—it is processed first. At the time of writing, the LLVM included in FreeBSD src is still LLVM 21. The source file specifying the version number is located at lib/clang/include/clang/Basic/Version.inc:
Installing Clang from Ports
The Clang version included in the base system may be too old to meet daily needs, so a newer version of Clang needs to be installed from Ports.
Install using pkg:
Or install using Ports:
Overview of Some C/C++ Development Tools on FreeBSD
The open-source version of Visual Studio Code, with Microsoft's proprietary components and telemetry removed; a full-featured extensible code editor
TypeScript / JavaScript (Electron framework)
Light to medium (approaches IDE functionality through extensions)
A cross-platform integrated development environment (IDE) designed for C/C++ development, providing intelligent code assistance, refactoring, and deep debugging integration; suitable for large projects
Java (based on IntelliJ platform)
Full IDE
A high-performance modern code editor created by the makers of Atom and Tree-sitter, focused on speed and fluidity with built-in collaboration features
Rust
Light to medium (high native performance, but focused on editing)
References
Jianping-Duan. algcl[EB/OL]. [2026-03-26]. https://github.com/Jianping-Duan/algcl. Provides C language algorithm and data structure programming examples that can run directly on FreeBSD.
Zed Industries. Zed[EB/OL]. [2026-04-17]. https://zed.dev/. A high-performance code editor developed by the creators of Atom and Tree-sitter.
Developing C/C++ with VSCode (Code-OSS)
C and C++ share high similarity in syntax, toolchains, and compilation processes. This section uses C as an example to introduce development environment configuration; C++ development can be configured similarly.
Visual Studio Code is a tool that combines the simplicity of a code editor with core development features (editing, building, debugging), providing comprehensive editing and debugging support, an extensibility model, and lightweight integration with existing tools.
Installing VS Code
Install using pkg:
Or install using Ports:
VS Code installed this way is actually Code-OSS. The main differences between Code-OSS and VS Code are the license and the available proprietary resources, similar to the relationship between Chromium and Chrome. See the original text for details on the differences.
Currently, Microsoft's Python extension and LLVM's clangd extension can run directly on Code-OSS, but the settings sync service is temporarily unavailable.
Setting Up Chinese Language Environment


Installing Required Software
Install the relevant tools so that they can run and debug properly in the editor.
Install using pkg:
Install using Ports:
Optional: Install the GNU toolchain gcc and gdb.
Installing Required Extensions
The VS Code in FreeBSD Ports is actually the open-source version Code-OSS of Visual Studio Code. This version has removed Microsoft's proprietary components and telemetry features, so it cannot directly access Microsoft's official extension marketplace, nor can it install or use the official C/C++ extension that depends on Microsoft's proprietary libraries.
Please follow these steps to install the required extensions:
Open the VS Code Extensions view (Ctrl+Shift+X).
Search for and install the following three extensions:
llvm-vs-code-extensions.vscode-clangd: A Clang-based language server providing code completion, syntax checking, go-to-definition, and other features.webfreak.debug: A debug adapter client that supports integration with multiple debugger backends (such as lldb-mi).KylinIdeTeam.cppdebug: A debugging extension designed for C/C++, working with debuggers like lldb-mi to enable breakpoints, variable watching, and other debugging capabilities.
This section selects three typical combinations as examples, corresponding to the debug adapter lldb-mi, and the build systems CMake + Ninja and Meson + Ninja. This section uses Visual Studio Code as the frontend development environment to illustrate how to integrate these underlying tools in the editor.
Debugger Integration: Configuration Based on lldb-mi
First, navigate to the project root directory (i.e., the test folder), which contains the main.c file. There should be a hidden folder .vscode in this directory (create it manually if it does not exist).
File structure:
Then, create two VS Code configuration files in the .vscode folder: launch.json for defining the debugger startup parameters and behavior, and tasks.json for configuring the build task execution flow.
Related file structure:
Once ready, write the following in the launch.json file:
Write the following in the tasks.json file:
After that, you can use VS Code's Run and Debug feature.
Build System Integration: CMake + Ninja
CMake is needed, so create a CMakeLists.txt file in the project root directory.
Write the following content in the CMakeLists.txt file:
Tip
This is the simplest CMake configuration and should be adjusted according to actual needs.
Similarly, create launch.json and tasks.json files in the .vscode directory.
Write the following in the launch.json file:
Write the following in the tasks.json file:
Build System Integration: Meson + Ninja
The Meson build system uses meson.build as its core configuration file for defining project build rules.
Create a meson.build file in the project root directory and write:
Tip
This is the simplest Meson configuration and should be adjusted according to actual needs.
Then, create launch.json and tasks.json files in the .vscode directory.
Write the following in the launch.json file:
Write the following in the tasks.json file:
Developing C/C++ with CLion
Installing CLion
Install using pkg:
Or build using Ports:
File Structure
Configuring CLion
CLion uses CMake, so the setup is simpler than VS Code—just configure the CMakeLists.txt file correctly (refer to the VS Code configuration above), which will not be repeated here.
Note
When developing C/C++ projects with CLion on FreeBSD, unless there are special circumstances, it is recommended to prioritize the
gccandgdbtoolchain to avoid potential errors.
Troubleshooting
CLion obtained from FreeBSD package sources may fail to start properly and display the following error:
To fix this issue, edit CLion's /usr/local/share/jetbrains/clion/plugins/plugin-classpath.txt file, remove any garbled characters (delete up to <idea-plugin>), and restart CLion to launch normally.

References
FreeBSD Bugzilla. Bug 290663 - devel/jetbrains-clion: fails to start[EB/OL]. [2026-03-26]. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=290663. This bug documents the CLion startup issue on FreeBSD and its solution.
Developing C/C++ with Zed
Installing Zed
Install using pkg:
Or build using Ports:
Configuring Zed
Zed's debugging functionality is primarily implemented through the Debug Adapter Protocol (DAP) and relies by default on specific debug adapters such as CodeLLDB (for the LLDB backend) or GDB to support debugging in multiple languages including Rust and C/C++. CodeLLDB, as the primary LLDB DAP adapter, officially supports only Linux, macOS, and Windows—FreeBSD and other BSD variants are not included. This means that in the FreeBSD environment, the CodeLLDB debug path is unavailable by default, limiting Zed's built-in debugging functionality.
Zed itself supports LLDB as a debugging backend (for example, when debugging Zed's own source code, it can be done via rust-lldb), but its general debugging system strictly depends on the DAP protocol rather than LLDB's Machine Interface (MI) (such as LLDB-MI). Therefore, directly integrating LLDB-MI is not a standard approach supported by Zed. If LLDB is needed, it must be implemented through a compatible DAP adapter (such as CodeLLDB or the official lldb-dap), and these adapters either lack official support or have compatibility issues on FreeBSD.
Theoretically, one could try configuring other DAP adapters through Zed's extension system to achieve debugging support, but FreeBSD is not an officially supported platform for Zed. Therefore, even if GDB debugging can run in Zed on FreeBSD, its behavior is essentially the same as using GDB directly in a terminal—only wrapped in Zed's graphical interface—still requiring manual command input.
Given the above, at the current stage Zed can be positioned as a pure code editor for coding and text editing, while delegating program building, running, and debugging to command-line tools (such as clang, ninja, lldb, gdb) or other debugging frontends.

Troubleshooting and Unfinished Business
Discussion Questions
The development methods introduced in this section primarily focus on compilers, debuggers, and basic build tools, and do not include highly customizable editors such as Neovim and Emacs as core recommendations.
The functionality and configuration of these tools have been briefly described in other chapters of this book.
However, every developer's learning habits and goals are different:
Do you believe that investing significant time in configuring and beautifying an editor can substantially improve your coding ability or learning efficiency?
At the beginner stage, how do you weigh focusing on understanding language features, system interfaces, and debugging techniques versus immersing yourself in tool customization?
Some view deep toolchain customization as a form of "philosophy of suffering" (taking pride in complex configurations). Do you think this perspective applies to the learning path?
Please carefully choose a development environment and workflow that suits your actual needs and long-term goals.
Last updated