Skip to content

Commit

Permalink
Merge pull request #1200 from Max-zs/main
Browse files Browse the repository at this point in the history
Edit the contents of the build.zn-cn.md and build.md document for source code build instruction
  • Loading branch information
windcbf authored Sep 22, 2024
2 parents 27bbc60 + ccaa589 commit 88e62e0
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 7 deletions.
137 changes: 137 additions & 0 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,144 @@ permalink: /build/

# Build OpenNHP Source Code
{: .fs-9 }
## 1. WSL Environment Setup

**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.

![Windows 10 on WSL Settings](/images/win10wsl.png)

- **【Install Linux on WSL】** It is recommended to install Ubuntu Linux on WSL by running the following command through PowerShell:

```bat
wsl --update
wsl --install -d Ubuntu
```

If you encounter the following problems, refer to:<https://blog.csdn.net/weixin_44293949/article/details/121863559>

```text
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. System requirement

- 2.1 'Go Language' environment: **Go 1.18** or above. Installation package download: <https://go.dev/dl/>
- **Windows and macOS**Environment, install Go through the downloaded installer.
- **Linux** environment can be installed directly through the management tool: `sudo apt install golang`
- After the installation is successful, run the command `go version`to see the Go version number.
- **Windows and macOS**environment,Install Go through the downloaded installer.
- **Linux**Environment can be installed directly through the management tool:`sudo apt install golang` Or install it manually with the following command:

```bash
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
```

- After the installation is successful, run the command `go version` to see the Go version number.
- 2.2 `GCC`environment:
- **Linux and macOS****GCC 8.0**or above。
- To view the GCC version of the command:`gcc -v`
- To install GCC: `sudo apt install build-essential`
- **Windows**:
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/>.

![install_msys2](/images/install_msys2.png)

2. Step 2: **Install GCC**. Enter the command in msys2's console:

```bash
pacman -S mingw-w64-ucrt-x86_64-gcc
```

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

```bat
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*
```bat
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 >
- 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:
```bat
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 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>
- 2.3 `lib`environment:
- 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
- Open the `build.bat` file and find it
```bat
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
```
- Change the installation path to your own visual studio directory. For example:
```bat
call "F:\develop\visualstu\VC\Auxiliary\Build\vcvarsall.bat" x64
```
## 3. compile
1. Pull the code repository
```bash
git clone https://github.com/OpenNHP/opennhp.git
```
2. Go environment Settings
```bash
go env -w GOPROXY="https://goproxy.cn,direct"
```
3. Compile and build
- **Linux and macOS**:Run the script in the code root directory
`make`
- **Windows**:Run the *BAT* file in the code root directory
`build.bat`<br>
<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>
## 4. result
Compiled binaries are in the code directory under the `release` subdirectory.
- **NHP-Server** executable and configuration files: `release\nhp-server` subdirectory
- **NHP-AC** executable and configuration files: `release\nhp-ac` subdirectory
- **NHP-Agent** executable and configuration files: `release\nhp-agent` subdirectory
- All binaries are packaged into a `tar` file: `release\archive` subdirectory
[中文版](/zh-cn/build/){: .label .fs-4 }
---
Expand Down
42 changes: 35 additions & 7 deletions docs/zh-cn/build.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ permalink: /zh-cn/build/

- **【WSL环境的IP地址】** 在WSL的Linux环境中,运行以下命令获取IP地址:

| 主机 | 查看IP地址的命令 |
|:--:|:--:|
| WSL中Linux主机 | `hostname -I \| awk '{print $1}'` |
| WSL宿主Windows主机 | `ip route show \| grep -i default \| awk '{ print $3}'` |
| 主机 | 查看IP地址的命令 |
| :----------------: | :-----------------------------------------------------: |
| WSL中Linux主机 | `hostname -I \| awk '{print $1}'` |
| WSL宿主Windows主机 | `ip route show \| grep -i default \| awk '{ print $3}'` |

## 2. 系统需求

- 2.1 `Go语言`环境:**Go 1.18** 或以上。安装包下载地址: <https://go.dev/dl/>
- **Windows与macOS**环境下,通过下载的安装程序来安装Go。
- **Linux**环境下可以直接通过管理工具安装: `sudo apt install golang `
- **Linux**环境下可以直接通过管理工具安装: `sudo apt install golang `
- 安装成功后,运行命令`go version` 来查看Go版本号。
- **Windows与macOS**环境下,通过下载的安装程序来安装Go。
- **Linux**环境下可以直接通过管理工具安装:`sudo apt install golang` 或者通过以下命令手动安装:
Expand Down Expand Up @@ -88,7 +88,34 @@ permalink: /zh-cn/build/
```bat
wsl --install --distribution Ubuntu-22.04
```
<small>*注:如果 2.1 和 2.2 已完成,直接在项目目录下执行编译命令 `.\build.bat` 时,通常会遇到 `系统找不到指定的路径`` 'lib' 不是内部或外部命令,也不是可运行的程序或批处理文件。` 的错误。2.3 提供了解决该问题的方法,供参考使用。*</small>
- 2.3 `lib`环境:
- 在编译运行的命令中使用了 lib 工具,这是用于生成 .lib 文件的工具,通常用于链接静态库或导出符号表(在 Windows 中生成 .lib 文件以便与 .dll 文件配合使用)。遇到的错误提示 lib 不是内部或外部命令,表示系统找不到 lib 工具。
- **解决('lib' 不是内部或外部命令,也不是可运行的程序或批处理文件)问题 :** 安装 Visual Studio 和 Visual Studio tools。
- lib 工具是微软的库管理工具,通常随 Visual Studio 的 Microsoft Build Tools 安装。确保你已安装 Visual Studio,并且选择了 C++ 生成工具(C++ Build Tools)组件,其中包括 lib.exe。
- 如果还没有安装 Visual Studio,可以从 Visual Studio 官方网站下载安装:https://visualstudiomicrosoft.com/zh-hans/ 安装时,选择“桌面开发(C++)”工作负载,它包含 lib.exe 及其他必要的工具。
- 安装 Visual Studio 后,确保使用 Visual Studio 开发者命令行(Developer Command Prompt) 来运行包含 lib 命令的 `build.bat `文件。这个命令行工具会自动加载构建工具的环境变量,如 lib.exe
- **解决(系统找不到指定路径的错误)问题 :** 更改`bulid.bat`文件中的路径
- 打开 `build.bat` 文件,找到
```bat
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
```
- 修改为你自己的 visual studio目录下安装路径。比如:
```bat
call "F:\develop\visualstu\VC\Auxiliary\Build\vcvarsall.bat" x64
```
## 3. 编译
1. 拉取代码仓库
Expand All @@ -107,7 +134,8 @@ permalink: /zh-cn/build/
- **Linux与macOS**:运行代码根目录下脚本
`make`
- **Windows**:运行代码根目录下*BAT*文件
`build.bat`
`build.bat`<br>
<small>*(注:如果在windows下编译过程中出现错误,请尝试此编译方法:在Visual Studio的developer command prompt for VS命令窗口中,切换到项目目录,执行`./build.bat`命令)*</small>
## 4. 结果
Expand Down

0 comments on commit 88e62e0

Please sign in to comment.