docs/dev/setup.md
This guide describes how to set up a development environment for Wazuh.
The recommended platform for development is Ubuntu 24.04.
The minimum toolchain requirements are:
For running unit tests, CMocka is required.
Install the required packages using apt:
apt install gcc g++ make cmake curl procps policycoreutils
apt install libcmocka-dev
Install the required packages and enable the GCC toolset:
dnf install make cmake gcc-toolset-13-gcc-c++ gcc-toolset-13-gcc procps policycoreutils
scl enable gcc-toolset-13 bash
# Install CMocka
dnf install dnf-plugins-core
dnf config-manager --enable crb
dnf install libcmocka-devel
To build the Windows agent, you need MinGW, CMocka, and Wine.
apt install gcc-mingw-w64-i686 g++-mingw-w64-i686 wine32
CMocka must be compiled from source for Windows cross-compilation:
git clone -b stable-1.1 https://git.cryptomilk.org/projects/cmocka.git
sed -Ei 's/(BUILD_SHARED_LIBS .+) ON/\1 OFF/' cmocka/DefineOptions.cmake
mkdir cmocka/build
cd cmocka/build
cmake -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc \
-DCMAKE_C_LINK_EXECUTABLE=i686-w64-mingw32-ld \
-DCMAKE_INSTALL_PREFIX=/usr/i686-w64-mingw32/ \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_BUILD_TYPE=Release ..
make
make install
cd ../..
rm -r cmocka
We recommend using Visual Studio Code for Wazuh development.
Install the following VS Code extensions for optimal development experience:
The following workspace settings are recommended for consistency with Wazuh coding standards. Create or update .vscode/settings.json:
{
"files.autoSave": "afterDelay",
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.simpleDialog.enable": true,
"editor.acceptSuggestionOnEnter": "off",
"workbench.editor.enablePreview": false,
"files.associations": {
"wazuh-manager.conf": "xml",
"ossec.conf": "xml",
"agent.conf": "xml"
},
"terminal.integrated.allowChords": false,
"terminal.integrated.scrollback": 100000,
"editor.rulers": [80]
}
files.trimTrailingWhitespace - Removes trailing whitespace on savefiles.insertFinalNewline - Ensures files end with a newlineeditor.rulers: [80] - Shows a vertical line at 80 characters for line length guidanceterminal.integrated.scrollback: 100000 - Increases terminal history for long build outputsBuild tasks automate compilation from within VS Code. Create or update .vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "build server",
"type": "shell",
"command": "make",
"args": ["TARGET=server", "DEBUG=1", "-j4"],
"options": {
"cwd": "${workspaceFolder}/src"
},
"group": "build",
"problemMatcher": ["$gcc"]
},
{
"label": "build agent",
"type": "shell",
"command": "make",
"args": ["TARGET=agent", "DEBUG=1", "-j4"],
"options": {
"cwd": "${workspaceFolder}/src"
},
"group": "build",
"problemMatcher": ["$gcc"]
},
{
"label": "build windows agent",
"type": "shell",
"command": "make",
"args": ["TARGET=winagent", "-j4"],
"options": {
"cwd": "${workspaceFolder}/src"
},
"group": "build",
"problemMatcher": ["$gcc"]
}
]
}
Running build tasks:
Ctrl+Shift+P (or Cmd+Shift+P on macOS) and search for "Tasks: Run Task"Ctrl+Shift+B to show all build tasksTask configuration notes:
DEBUG=1 - Compiles with debug symbols (-g flag) for debugging-j4 - Enables parallel compilation with 4 jobsproblemMatcher: ["$gcc"] - Parses compiler output to display errors in the Problems panelDebug configurations enable interactive debugging with GDB. Create or update .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug wazuh-manager-analysisd",
"type": "cppdbg",
"request": "launch",
"program": "/var/wazuh-manager/bin/wazuh-manager-analysisd",
"args": ["-f"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build server",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
Starting a debug session:
F5 or go to Run - Start DebuggingCtrl+Shift+D) and click the play buttonDebug configuration notes:
program - Path to the binary to debugargs - Command-line arguments passed to the programpreLaunchTask - Task to run before debugging (e.g., rebuild the binary)stopAtEntry - Set to true to pause at the program entry pointDEBUG=1)Additional debug configurations:
You can add more configurations for other Wazuh components:
{
"name": "Debug wazuh-manager-remoted",
"type": "cppdbg",
"request": "launch",
"program": "/var/wazuh-manager/bin/wazuh-manager-remoted",
"args": ["-f"],
"preLaunchTask": "build server",
"MIMode": "gdb"
}
After building, you may need to copy binaries to the installation directory. You can automate this with additional tasks:
{
"label": "deploy wazuh-manager-analysisd",
"type": "shell",
"command": "sudo",
"args": ["cp", "wazuh-manager-analysisd", "/var/wazuh-manager/bin/"],
"options": {
"cwd": "${workspaceFolder}/src"
},
"dependsOn": ["build server"]
}
Alternatively, link the preLaunchTask in your debug configuration to rebuild and deploy before each debug session.
If you encounter permission errors when debugging Wazuh binaries:
sudo code --user-data-dir=/root/.vscode-root --no-sandboxIf GDB is not installed:
apt-get install gdb # Ubuntu/Debian
yum install gdb # Rocky Linux/RHEL
Ensure all dependencies are installed and you're using the correct compiler version:
gcc --version # Should be 13 or higher
If code completion isn't working:
Ctrl+Shift+P)compilerPath and includePath settings are correct