Skip to content

Commit dd37e9f

Browse files
authored
Fix CPP client could not be successfully built on windows (#4665)
1 parent 2d6307f commit dd37e9f

File tree

3 files changed

+84
-91
lines changed

3 files changed

+84
-91
lines changed

compile-tools/thrift/pom.xml

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,8 @@
3333
<thrift.with.cpp>ON</thrift.with.cpp>
3434
<thrift.with.csharp>ON</thrift.with.csharp>
3535
<thrift.with.python>ON</thrift.with.python>
36-
<chmod.command>chmod</chmod.command>
37-
<chmod.command.para>+x cmake</chmod.command.para>
3836
</properties>
3937
<profiles>
40-
<profile>
41-
<id>os-windows</id>
42-
<activation>
43-
<os>
44-
<family>windows</family>
45-
</os>
46-
</activation>
47-
<properties>
48-
<chmod.command>echo</chmod.command>
49-
<chmod.command.para>"do nothing"</chmod.command.para>
50-
</properties>
51-
</profile>
5238
<profile>
5339
<id>compile-cpp</id>
5440
<build>
@@ -86,25 +72,6 @@
8672
</execution>
8773
</executions>
8874
</plugin>
89-
<plugin>
90-
<groupId>org.codehaus.mojo</groupId>
91-
<artifactId>exec-maven-plugin</artifactId>
92-
<version>1.6.0</version>
93-
<executions>
94-
<execution>
95-
<id>make-cmake-executable</id>
96-
<phase>generate-sources</phase>
97-
<goals>
98-
<goal>exec</goal>
99-
</goals>
100-
<configuration>
101-
<basedir>${cmake.root.dir}/bin</basedir>
102-
<executable>${chmod.command}</executable>
103-
<commandlineArgs>${chmod.command.para}</commandlineArgs>
104-
</configuration>
105-
</execution>
106-
</executions>
107-
</plugin>
10875
<plugin>
10976
<groupId>com.googlecode.cmake-maven-project</groupId>
11077
<artifactId>cmake-maven-plugin</artifactId>

docs/UserGuide/API/Programming-Cpp-Native-API.md

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -117,35 +117,19 @@ The version of gcc and boost installed by yum is too low, therefore you should c
117117

118118
#### Build Thrift on Windows
119119

120+
- building environment
121+
120122
Make sure a complete Windows C++ building environment is prepared on your machine.
121123
MSVC, MinGW... are supported.
122124

123125
If you are using MS Visual Studio, remember to install Visual Studio C/C++ IDE and compiler(supporting CMake, Clang, MinGW).
124126

125-
- Flex and Bison
126-
Windows Flex and Bison could be downloaded from SourceForge: https://sourceforge.net/projects/winflexbison/
127-
128-
After downloaded, please rename the executables to flex.exe and bison.exe and add them to "PATH" environment variables.
129-
130-
- Boost
131-
For Boost, please download from the official website: https://www.boost.org/users/download/
132-
133-
Then build Boost by executing bootstrap.bat and b2.exe.
134-
```powershell
135-
bootstrap.bat
136-
.\b2.exe
137-
```
138-
139-
To help CMake find your Boost libraries on windows, you should set `-Dboost.include.dir=${your boost header folder} -Dboost.library.dir=${your boost lib (stage) folder}`
140-
to your mvn build command.
127+
- CMake
141128

142-
143-
144-
#### Cmake generator on Windows
129+
For CMake, please download from the official website: https://cmake.org/download/
145130

146131
There is a long list of supported Cmake generators on Windows environment.
147132

148-
149133
```
150134
Visual Studio 16 2019 = Generates Visual Studio 2019 project files.
151135
Use -A option to specify architecture.
@@ -181,29 +165,55 @@ the list is available via command: `cmake --help`
181165
When building client-cpp project, use -Dcmake.generator="" option to specify a Cmake generator.
182166
E.g., `mvn package -Dcmake.generator="Visual Studio 15 2017 [arch]"`
183167

168+
- Flex and Bison
169+
170+
Windows Flex and Bison could be downloaded from SourceForge: https://sourceforge.net/projects/winflexbison/
184171

172+
After downloaded, please rename the executables to flex.exe and bison.exe and add them to "PATH" environment variables.
185173

174+
- Boost
186175

187-
#### Building C++ Client
176+
For Boost, please download from the official website: https://www.boost.org/users/download/
188177

178+
Then build Boost by executing bootstrap.bat and b2.exe.
179+
```powershell
180+
bootstrap.bat
181+
.\b2.exe
182+
```
189183

190-
To compile cpp client, add "-P compile-cpp" option to maven build command.
184+
To help CMake find your Boost libraries on windows, you should set `-Dboost.include.dir=${your boost header folder} -Dboost.library.dir=${your boost lib (stage) folder}`
185+
to your mvn build command.
191186

192-
The compiling requires the module "compile-tools" to be built first.
187+
- openssl
188+
189+
For openssl , download Source code from the official website: https://www.openssl.org/source/
193190

191+
download binary files from http://slproweb.com/products/Win32OpenSSL.html
194192

193+
- Add Path
194+
195+
Before compile,make sure cmake,flex,bison and openssl already add to "PATH" environment variables.
195196

196197
#### Compile and Test
197198

199+
To compile cpp client, add "-P compile-cpp" option to maven build command.
200+
201+
The compiling requires the module "compile-tools" to be built first.
202+
203+
- On Mac and Linux, the command to compile cpp-client is as follows:
204+
198205
`mvn package -P compile-cpp -pl example/client-cpp-example -am -DskipTest`
199206

200-
To compile on Windows, please install Boost first and add following Maven settings:
207+
- On Windwos , Compile cpp-client
208+
209+
please install Boost first and add following Maven settings before compile on Windows:
201210
```shell
202211
-Dboost.include.dir=${your boost header folder} -Dboost.library.dir=${your boost lib (stage) folder}`
203212
```
213+
Add generator for cmake:
214+
`-Dcmake.generator="Visual Studio 15 2017 [arch]"`
204215

205-
e.g.,
206-
216+
The complete command:
207217
```shell
208218
mvn package -P compile-cpp -pl client-cpp,server,example/client-cpp-example -am
209219
-D"boost.include.dir"="D:\boost_1_75_0" -D"boost.library.dir"="D:\boost_1_75_0\stage\lib" -DskipTests

docs/zh/UserGuide/API/Programming-Cpp-Native-API.md

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -97,32 +97,15 @@ sudo yum install bison flex openssl-devel
9797

9898
#### 在 Windows 上编译 Thrift
9999

100+
- 编译构建环境
101+
100102
保证你的 Windows 系统已经搭建好了完整的 C/C++的编译构建环境。可以是 MSVC,MinGW 等。
101103

102104
如使用 MS Visual Studio,在安装时需要勾选 Visual Studio C/C++ IDE and compiler(supporting CMake, Clang, MinGW)。
103105

104-
- Flex 和 Bison
105-
106-
Windows 版的 Flex 和 Bison 可以从 SourceForge 下载:https://sourceforge.net/projects/winflexbison/
107-
108-
下载后需要将可执行文件重命名为 flex.exe 和 bison.exe 以保证编译时能够被找到,添加可执行文件的目录到 PATH 环境变量中。
109-
110-
- Boost
111-
112-
Boost 官网下载新版本 Boost: https://www.boost.org/users/download/
113-
114-
依次执行 bootstrap.bat 和 b2.exe,本地编译 boost
115-
116-
```shell
117-
bootstrap.bat
118-
.\b2.exe
119-
```
120-
121-
为了帮助 CMake 本地安装好的 Boost,在编译 client-cpp 的 mvn 命令中需添加:
122-
123-
`-Dboost.include.dir=${your boost header folder} -Dboost.library.dir=${your boost lib (stage) folder}`
106+
- CMake
124107

125-
#### CMake 生成器
108+
CMake 官网下载地址 https://cmake.org/download/
126109

127110
CMake 需要根据不同编译平台使用不同的生成器。CMake 支持的生成器列表如下 (`cmake --help`的结果):
128111

@@ -158,32 +141,65 @@ CMake 需要根据不同编译平台使用不同的生成器。CMake 支持的
158141
```
159142

160143
编译 client-cpp 时的 mvn 命令中添加 -Dcmake.generator="" 选项来指定使用的生成器名称。
144+
161145
`mvn package -Dcmake.generator="Visual Studio 15 2017 [arch]"`
162146

163-
#### 编译 C++ 客户端
147+
- Flex 和 Bison
164148

165-
Maven 命令中添加"-P client-cpp" 选项编译 client-cpp 模块。client-cpp 需要依赖编译好的 thrift,即 compile-tools 模块。
149+
Windows 版的 Flex 和 Bison 可以从 SourceForge 下载:https://sourceforge.net/projects/winflexbison/
166150

167-
#### 编译及测试
151+
下载后需要将可执行文件重命名为 flex.exe 和 bison.exe 以保证编译时能够被找到,添加可执行文件的目录到 PATH 环境变量中。
168152

169-
完整的 C++客户端命令如下:
153+
- Boost
170154

171-
`mvn package -P compile-cpp -pl example/client-cpp-example -am -DskipTest`
155+
Boost 官网下载地址 https://www.boost.org/users/download/
172156

173-
注意在 Windows 下需提前安装好 Boost,并添加以下 Maven 编译选项:
157+
依次执行 bootstrap.bat 和 b2.exe,本地编译 boost
174158

175159
```shell
176-
-Dboost.include.dir=${your boost header folder} -Dboost.library.dir=${your boost lib (stage) folder}`
160+
bootstrap.bat
161+
b2.exe
177162
```
178163

179-
例如:
164+
为了帮助 CMake 本地安装好的 Boost,在编译 client-cpp 的 mvn 命令中需添加:
165+
166+
`-Dboost.include.dir=${your boost header folder} -Dboost.library.dir=${your boost lib (stage) folder}`
167+
168+
- openssl
169+
170+
openssl 官网源码下载地址 https://www.openssl.org/source/
171+
172+
二进制文件下载地址 http://slproweb.com/products/Win32OpenSSL.html
173+
174+
- 增加环境变量
175+
176+
在编译前,需要确定cmake,flex,bison,openssl都加入了PATH。
177+
178+
#### 编译及测试
179+
180+
Maven 命令中添加"-P client-cpp" 选项编译 client-cpp 模块。client-cpp 需要依赖编译好的 thrift,即 compile-tools 模块。
181+
182+
- Mac , Linux 下,编译C++客户端完整命令如下:
183+
184+
`mvn package -P compile-cpp -pl example/client-cpp-example -am -DskipTest`
185+
186+
- Windows下,编译C++客户端:
187+
188+
编译前需额外添加Boost相关的参数:
189+
190+
`-Dboost.include.dir=${your boost header folder} -Dboost.library.dir=${your boost lib (stage) folder}`
191+
192+
需指定cmake的generator,例如:
193+
194+
`-Dcmake.generator="Visual Studio 15 2017 [arch]"`
195+
196+
完整编译C++客户端命令如下:
180197

181198
```shell
182-
mvn package -P compile-cpp -pl client-cpp,server,example/client-cpp-example -am
183-
-D"boost.include.dir"="D:\boost_1_75_0" -D"boost.library.dir"="D:\boost_1_75_0\stage\lib" -DskipTests
199+
mvn package -P compile-cpp -pl client-cpp,server,example/client-cpp-example -am -Dcmake.generator="your cmake generator" -Dboost.include.dir=${your boost header folder} -Dboost.library.dir=${your boost lib (stage) folder} -DskipTests
184200
```
185201

186-
编译成功后,打包好的zip 文件将位于:"client-cpp/target/client-cpp-${project.version}-cpp-${os}.zip"
202+
编译成功后,打包好的 zip 文件将位于:"client-cpp/target/client-cpp-${project.version}-cpp-${os}.zip"
187203

188204
解压后的目录结构如下图所示 (Mac):
189205

0 commit comments

Comments
 (0)