docs/build.md
{: .fs-9 }
This article explains how to build OpenNHP from source code. {: .fs-6 .fw-300 }
中文版{: .label .fs-4 }
Note: You can run Linux through the WSL subsystem on Windows 10/11. For details, see the official WSL documentation: https://learn.microsoft.com/en-us/windows/wsl/install
【Enable the WSL function】 On Win10, you need to enable WSL first to use it for installing Linux. See the settings interface in the image below.
【Install Linux on WSL】 It is recommended to install Ubuntu Linux on WSL by running the following command through PowerShell:
wsl --update
wsl --install -d Ubuntu
If you encounter the following problems, refer to:https://blog.csdn.net/weixin_44293949/article/details/121863559
From 'https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json' to extract the distribution list. The server name or address could not be resolved
Error code: Wsl/WININET_E_NAME_NOT_RESOLVED
【IP address of the WSL environment】 In the Linux environment of WSL, run the following command to get the IP address:
| Host machine | Command to view the IP address |
|---|---|
| Linux hosts in WSL | hostname -I | awk '{print $1}' |
| WSL hosts the Windows host | ip route show | grep -i default | awk '{ print $3}' |
2.1 'Go Language' environment: Go 1.23 . Installation package download: https://go.dev/dl/
sudo apt install golanggo versionto see the Go version number.sudo apt install golang Or install it manually with the following command: 1. sudo apt-get update
2. wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz
3. sudo tar -xvf go1.21.0.linux-amd64.tar.gz
4. sudo mv go /usr/local
5. export GOROOT=/usr/local/go
6. export GOPATH=$HOME/go
7. export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
8. source ~/.profile
go version to see the Go version number.2.2 GCCenvironment:
Linux and macOS:GCC 8.0or above。
gcc -vsudo apt install build-essentialWindows:
Step 2: Install GCC. Enter the command in msys2's console:
pacman -S mingw-w64-ucrt-x86_64-gcc
Step 3: Configure GCC. Add the GCC tool PATH to the Windows %PATH% environment variable. For example, if the installation path of mingw-w64-gcc isC:\Program Files\MSYS2\ , run the command
setx PATH "%PATH%;C:\Program Files\MSYS2\ucrt64\bin
After successful execution, open a new command line window and check the version number of gcc
gcc --version
Tip: Under Windows can be WSL subsystem to run Linux, details please see WSL official document: < https://learn.microsoft.com/zh-cn/windows/wsl/install >
wsl --install --distribution Ubuntu-22.04
<small>Note: If 2.1 and 2.2 are complete, when executing the compile command .\build.bat directly in the project directory, you will usually encounterthe system cannot find the specified pathor 'lib' is not an internal or external command, nor is it a runnable program or batch fileThe mistake. 2.3 Provides a solution to this problem for reference.</small>
2.3 libenvironment:
The lib utility is used in the compile run command, which is a tool for generating.lib files, usually for linking static libraries or exporting symbol tables (the.lib file is generated in Windows to work with the.dll file). The error message lib is not an internal or external command, indicating that the system cannot find the lib utility.
To solve the problem ('lib' is not an internal or external command, nor is it a runnable program or batch file) : Install Visual Studio and Visual Studio tools.
The lib tool is Microsoft's library management tool and is usually installed with Microsoft Build Tools for Visual Studio. Make sure you have Visual Studio installed and have selected the C++ Build Tools components, including lib.exe.
If you do not have Visual Studio installed, you can download and install it from the official Visual Studio website: https://visualstudiomicrosoft.com/zh-hans/ when installation, select the desktop development (c + +) "the workload, it contains the lib. Exe and other necessary tools.
After installing Visual Studio, make sure to use the Visual Studio Developer Command Prompt to run the build.bat file that contains the lib command. This command line tool automatically loads environment variables for the build tool, such as lib.exe
To resolve the problem (the system cannot find the specified path) : Change the path in the build.bat file
build.bat file and find itcall "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
call "F:\develop\visualstu\VC\Auxiliary\Build\vcvarsall.bat" x64
2.4 clang environment (optional):
clang --versionsudo apt install clang llvm libbpf-devsudo yum install clang llvm libbpf-dev -yPull the code repository
git clone https://github.com/OpenNHP/opennhp.git
Go environment Settings
go env -w GOPROXY="https://goproxy.cn,direct"
Compile and build
makebuild.bat<small>(Note: If an error occurs during the compilation process under windows, try this compilation method: In the Visual Studio developer command prompt for VS command window, switch to the project directory and execute the ./build.bat command)</small>
make ebpf<small>(Note: The command make ebpf will also compile the eBPF module)</small>
Compiled binaries are in the code directory under the release subdirectory.
release\nhp-server subdirectoryrelease\nhp-ac subdirectoryrelease\nhp-agent subdirectoryrelease\nhp-db subdirectoryrelease\nhp-kgc subdirectorytar file: release\archive subdirectory中文版{: .label .fs-4 }