|
1 | | ---- |
2 | | -layout: page |
3 | | -title: How to Build |
4 | | -nav_order: 6 |
5 | | -permalink: /build/ |
6 | | ---- |
7 | | - |
8 | | -# Build OpenNHP Source Code |
9 | | -{: .fs-9 } |
10 | | - |
11 | | -This article explains how to build OpenNHP from source code. |
12 | | -{: .fs-6 .fw-300 } |
13 | | - |
14 | | -[中文版](/zh-cn/build/){: .label .fs-4 } |
15 | | - |
16 | | ---- |
17 | | - |
18 | | -## 1. WSL Environment Setup |
19 | | - |
20 | | -**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 |
21 | | - |
22 | | -- **【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. |
23 | | - |
24 | | -  |
25 | | - |
26 | | -- **【Install Linux on WSL】** It is recommended to install Ubuntu Linux on WSL by running the following command through PowerShell: |
27 | | - |
28 | | - ```bat |
29 | | - wsl --update |
30 | | - wsl --install -d Ubuntu |
31 | | - ``` |
32 | | - |
33 | | - If you encounter the following problems, refer to:<https://blog.csdn.net/weixin_44293949/article/details/121863559> |
34 | | - |
35 | | - ```text |
36 | | - 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 |
37 | | - Error code: Wsl/WININET_E_NAME_NOT_RESOLVED |
38 | | - ``` |
39 | | - |
40 | | -- **【IP address of the WSL environment】** In the Linux environment of WSL, run the following command to get the IP address: |
41 | | - |
42 | | -| Host machine | Command to view the IP address | |
43 | | -| :------------------------: | :-----------------------------------------------------: | |
44 | | -| Linux hosts in WSL | `hostname -I \| awk '{print $1}'` | |
45 | | -| WSL hosts the Windows host | `ip route show \| grep -i default \| awk '{ print $3}'` | |
46 | | - |
47 | | -## 2. System requirement |
48 | | - |
49 | | -- 2.1 'Go Language' environment: **Go 1.21** . Installation package download: <https://go.dev/dl/> |
50 | | - - **Windows and macOS**Environment, install Go through the downloaded installer. |
51 | | - - **Linux** environment can be installed directly through the management tool: `sudo apt install golang` |
52 | | - - After the installation is successful, run the command `go version`to see the Go version number. |
53 | | - - **Windows and macOS**environment,Install Go through the downloaded installer. |
54 | | - - **Linux**Environment can be installed directly through the management tool:`sudo apt install golang` Or install it manually with the following command: |
55 | | - |
56 | | - ```bash |
57 | | - 1. sudo apt-get update |
58 | | - 2. wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz |
59 | | - 3. sudo tar -xvf go1.21.0.linux-amd64.tar.gz |
60 | | - 4. sudo mv go /usr/local |
61 | | - 5. export GOROOT=/usr/local/go |
62 | | - 6. export GOPATH=$HOME/go |
63 | | - 7. export PATH=$GOPATH/bin:$GOROOT/bin:$PATH |
64 | | - 8. source ~/.profile |
65 | | - ``` |
66 | | - |
67 | | - - After the installation is successful, run the command `go version` to see the Go version number. |
68 | | -- 2.2 `GCC`environment: |
69 | | - - **Linux and macOS**:**GCC 8.0**or above。 |
70 | | - - To view the GCC version of the command:`gcc -v` |
71 | | - - To install GCC: `sudo apt install build-essential` |
72 | | - - **Windows**: |
73 | | - 1. Step 1: **Install mingw64**. mingw64 can be downloaded from msys2's package management tool. Installation requirements, downloads, and installation tutorials for msys2 are available at <https://www.msys2.org/>. |
74 | | - |
75 | | -  |
76 | | - |
77 | | - 2. Step 2: **Install GCC**. Enter the command in msys2's console: |
78 | | - |
79 | | - ```bash |
80 | | - pacman -S mingw-w64-ucrt-x86_64-gcc |
81 | | - ``` |
82 | | - |
83 | | - 3. 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 is`C:\Program Files\MSYS2\ `, run the command |
84 | | - |
85 | | - ```bat |
86 | | - setx PATH "%PATH%;C:\Program Files\MSYS2\ucrt64\bin |
87 | | - ``` |
88 | | - After successful execution, open a new command line window and check the version number of *gcc* |
89 | | - ```bat |
90 | | - gcc --version |
91 | | - ``` |
92 | | -
|
93 | | - - **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 > |
94 | | - - It is recommended to run the latest version of Ubuntu v22 on WSL and install it by running the following command from PowerShell on Windows: |
95 | | - ```bat |
96 | | - wsl --install --distribution Ubuntu-22.04 |
97 | | - ``` |
98 | | -
|
99 | | -<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 encounter` the system cannot find the specified path `or` 'lib' is not an internal or external command, nor is it a runnable program or batch file`The mistake. 2.3 Provides a solution to this problem for reference.*</small> |
100 | | -
|
101 | | -- 2.3 `lib`environment: |
102 | | -
|
103 | | -
|
104 | | - - 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. |
105 | | -
|
106 | | - - **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. |
107 | | -
|
108 | | - - 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. |
109 | | -
|
110 | | - - 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. |
111 | | -
|
112 | | - - 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 |
113 | | -
|
114 | | - - **To resolve the problem (the system cannot find the specified path) :** Change the path in the `build.bat` file |
115 | | -
|
116 | | - - Open the `build.bat` file and find it |
117 | | - ```bat |
118 | | - call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 |
119 | | - ``` |
120 | | -
|
121 | | - - Change the installation path to your own visual studio directory. For example: |
122 | | - ```bat |
123 | | - call "F:\develop\visualstu\VC\Auxiliary\Build\vcvarsall.bat" x64 |
124 | | - ``` |
125 | | -
|
126 | | -## 3. compile |
127 | | -
|
128 | | -1. Pull the code repository |
129 | | -
|
130 | | - ```bash |
131 | | - git clone https://github.com/OpenNHP/opennhp.git |
132 | | - ``` |
133 | | -
|
134 | | -2. Go environment Settings |
135 | | -
|
136 | | - ```bash |
137 | | - go env -w GOPROXY="https://goproxy.cn,direct" |
138 | | - ``` |
139 | | -
|
140 | | -3. Compile and build |
141 | | - - **Linux and macOS**:Run the script in the code root directory |
142 | | - `make` |
143 | | - - **Windows**:Run the *BAT* file in the code root directory |
144 | | - `build.bat`<br> |
145 | | - <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> |
146 | | -
|
147 | | -## 4. result |
148 | | -
|
149 | | -Compiled binaries are in the code directory under the `release` subdirectory. |
150 | | -
|
151 | | -- **NHP-Server** executable and configuration files: `release\nhp-server` subdirectory |
152 | | -- **NHP-AC** executable and configuration files: `release\nhp-ac` subdirectory |
153 | | -- **NHP-Agent** executable and configuration files: `release\nhp-agent` subdirectory |
154 | | -- **NHP-DB** executable and configuration files: `release\nhp-db` subdirectory |
155 | | -- All binaries are packaged into a `tar` file: `release\archive` subdirectory |
156 | | -
|
157 | | -[中文版](/zh-cn/build/){: .label .fs-4 } |
158 | | -
|
159 | | ---- |
160 | | -
|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: How to Build |
| 4 | +nav_order: 6 |
| 5 | +permalink: /build/ |
| 6 | +--- |
| 7 | + |
| 8 | +# Build OpenNHP Source Code |
| 9 | +{: .fs-9 } |
| 10 | + |
| 11 | +This article explains how to build OpenNHP from source code. |
| 12 | +{: .fs-6 .fw-300 } |
| 13 | + |
| 14 | +[中文版](/zh-cn/build/){: .label .fs-4 } |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## 1. WSL Environment Setup |
| 19 | + |
| 20 | +**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 |
| 21 | + |
| 22 | +- **【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. |
| 23 | + |
| 24 | +  |
| 25 | + |
| 26 | +- **【Install Linux on WSL】** It is recommended to install Ubuntu Linux on WSL by running the following command through PowerShell: |
| 27 | + |
| 28 | + ```bat |
| 29 | + wsl --update |
| 30 | + wsl --install -d Ubuntu |
| 31 | + ``` |
| 32 | + |
| 33 | + If you encounter the following problems, refer to:<https://blog.csdn.net/weixin_44293949/article/details/121863559> |
| 34 | + |
| 35 | + ```text |
| 36 | + 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 |
| 37 | + Error code: Wsl/WININET_E_NAME_NOT_RESOLVED |
| 38 | + ``` |
| 39 | + |
| 40 | +- **【IP address of the WSL environment】** In the Linux environment of WSL, run the following command to get the IP address: |
| 41 | + |
| 42 | +| Host machine | Command to view the IP address | |
| 43 | +| :------------------------: | :-----------------------------------------------------: | |
| 44 | +| Linux hosts in WSL | `hostname -I \| awk '{print $1}'` | |
| 45 | +| WSL hosts the Windows host | `ip route show \| grep -i default \| awk '{ print $3}'` | |
| 46 | + |
| 47 | +## 2. System requirement |
| 48 | + |
| 49 | +- 2.1 'Go Language' environment: **Go 1.23** . Installation package download: <https://go.dev/dl/> |
| 50 | + - **Windows and macOS**Environment, install Go through the downloaded installer. |
| 51 | + - **Linux** environment can be installed directly through the management tool: `sudo apt install golang` |
| 52 | + - After the installation is successful, run the command `go version`to see the Go version number. |
| 53 | + - **Windows and macOS**environment,Install Go through the downloaded installer. |
| 54 | + - **Linux**Environment can be installed directly through the management tool:`sudo apt install golang` Or install it manually with the following command: |
| 55 | + |
| 56 | + ```bash |
| 57 | + 1. sudo apt-get update |
| 58 | + 2. wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz |
| 59 | + 3. sudo tar -xvf go1.21.0.linux-amd64.tar.gz |
| 60 | + 4. sudo mv go /usr/local |
| 61 | + 5. export GOROOT=/usr/local/go |
| 62 | + 6. export GOPATH=$HOME/go |
| 63 | + 7. export PATH=$GOPATH/bin:$GOROOT/bin:$PATH |
| 64 | + 8. source ~/.profile |
| 65 | + ``` |
| 66 | + |
| 67 | + - After the installation is successful, run the command `go version` to see the Go version number. |
| 68 | +- 2.2 `GCC`environment: |
| 69 | + - **Linux and macOS**:**GCC 8.0**or above。 |
| 70 | + - To view the GCC version of the command:`gcc -v` |
| 71 | + - To install GCC: `sudo apt install build-essential` |
| 72 | + - **Windows**: |
| 73 | + 1. Step 1: **Install mingw64**. mingw64 can be downloaded from msys2's package management tool. Installation requirements, downloads, and installation tutorials for msys2 are available at <https://www.msys2.org/>. |
| 74 | + |
| 75 | +  |
| 76 | + |
| 77 | + 2. Step 2: **Install GCC**. Enter the command in msys2's console: |
| 78 | + |
| 79 | + ```bash |
| 80 | + pacman -S mingw-w64-ucrt-x86_64-gcc |
| 81 | + ``` |
| 82 | + |
| 83 | + 3. 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 is`C:\Program Files\MSYS2\ `, run the command |
| 84 | + |
| 85 | + ```bat |
| 86 | + setx PATH "%PATH%;C:\Program Files\MSYS2\ucrt64\bin |
| 87 | + ``` |
| 88 | + After successful execution, open a new command line window and check the version number of *gcc* |
| 89 | + ```bat |
| 90 | + gcc --version |
| 91 | + ``` |
| 92 | +
|
| 93 | + - **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 > |
| 94 | + - It is recommended to run the latest version of Ubuntu v22 on WSL and install it by running the following command from PowerShell on Windows: |
| 95 | + ```bat |
| 96 | + wsl --install --distribution Ubuntu-22.04 |
| 97 | + ``` |
| 98 | +
|
| 99 | +<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 encounter` the system cannot find the specified path `or` 'lib' is not an internal or external command, nor is it a runnable program or batch file`The mistake. 2.3 Provides a solution to this problem for reference.*</small> |
| 100 | +
|
| 101 | +- 2.3 `lib`environment: |
| 102 | +
|
| 103 | +
|
| 104 | + - 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. |
| 105 | +
|
| 106 | + - **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. |
| 107 | +
|
| 108 | + - 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. |
| 109 | +
|
| 110 | + - 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. |
| 111 | +
|
| 112 | + - 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 |
| 113 | +
|
| 114 | + - **To resolve the problem (the system cannot find the specified path) :** Change the path in the `build.bat` file |
| 115 | +
|
| 116 | + - Open the `build.bat` file and find it |
| 117 | + ```bat |
| 118 | + call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 |
| 119 | + ``` |
| 120 | +
|
| 121 | + - Change the installation path to your own visual studio directory. For example: |
| 122 | + ```bat |
| 123 | + call "F:\develop\visualstu\VC\Auxiliary\Build\vcvarsall.bat" x64 |
| 124 | + ``` |
| 125 | + |
| 126 | +- 2.4 `clang` environment (optional): |
| 127 | +
|
| 128 | + - **Note:** |
| 129 | + - Regarding the clang compiler tool, clang is only supported on Linux and not available on Windows, Windows don't need to install clang. |
| 130 | + - Regarding eBPF module compilation, eBPF is not supported on Windows, eBPF is only supported on Linux with kernel version 5.6 or higher. |
| 131 | + - To check clang version: `clang --version` |
| 132 | + - **For Linux Ubuntu**: |
| 133 | + - Install clang, llvm, and libbpf-dev: `sudo apt install clang llvm libbpf-dev` |
| 134 | + - **For Linux CentOS**: |
| 135 | + - Install clang, llvm, and libbpf-dev: `sudo yum install clang llvm libbpf-dev -y` |
| 136 | + |
| 137 | +
|
| 138 | +## 3. compile |
| 139 | +
|
| 140 | +1. Pull the code repository |
| 141 | +
|
| 142 | + ```bash |
| 143 | + git clone https://github.com/OpenNHP/opennhp.git |
| 144 | + ``` |
| 145 | +
|
| 146 | +2. Go environment Settings |
| 147 | +
|
| 148 | + ```bash |
| 149 | + go env -w GOPROXY="https://goproxy.cn,direct" |
| 150 | + ``` |
| 151 | +
|
| 152 | +3. Compile and build |
| 153 | + - **Linux and macOS**:Run the script in the code root directory |
| 154 | + `make` |
| 155 | + - **Windows**:Run the *BAT* file in the code root directory |
| 156 | + `build.bat`<br> |
| 157 | + <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> |
| 158 | + - **Compiling eBPF on Linux**: Run the script in the code root directory |
| 159 | + `make ebpf`<br> |
| 160 | + <small>*(Note: The command `make ebpf` will also compile the eBPF module)*</small> |
| 161 | +
|
| 162 | +## 4. result |
| 163 | +
|
| 164 | +Compiled binaries are in the code directory under the `release` subdirectory. |
| 165 | +
|
| 166 | +- **NHP-Server** executable and configuration files: `release\nhp-server` subdirectory |
| 167 | +- **NHP-AC** executable and configuration files: `release\nhp-ac` subdirectory |
| 168 | +- **NHP-Agent** executable and configuration files: `release\nhp-agent` subdirectory |
| 169 | +- **NHP-DB** executable and configuration files: `release\nhp-db` subdirectory |
| 170 | +- All binaries are packaged into a `tar` file: `release\archive` subdirectory |
| 171 | +
|
| 172 | +[中文版](/zh-cn/build/){: .label .fs-4 } |
| 173 | +
|
| 174 | +--- |
| 175 | +
|
0 commit comments