由于想在Windows下使用最新的iperf3,但iperf3 Windows版从3.1.3之后就没有更新了,于是尝试了下自己编译最新的iperf3版本。
编译准备
下载并安装cygwin, 安装所有Devel,在cygwin shell下载iperf3源码。
编译过程
cd iperf源码目录
./bootstrap.sh #可选
./configure
make
make install
报错处理
如果make中出现以下错误,需要修改cygwin的ossl_typ.h
文件((默认为:C:\cygwin64\usr\include\openssl\ossl_typ.h)):
$ make
Making all in src
make[1]: Entering directory '/iperf-3.6/src'
make all-am
make[2]: Entering directory '/iperf-3.6/src'
/bin/sh ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -g -O2 -Wall -MT iperf_api.lo -MD -MP -MF .deps/iperf_api.Tpo -c -o iperf_api.lo iperf_api.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -g -O2 -Wall -MT iperf_api.lo -MD -MP -MF .deps/iperf_api.Tpo -c iperf_api.c -DDLL_EXPORT -DPIC -o .libs/iperf_api.o
In file included from /usr/include/w32api/Windows.h:95:0,
from iperf_api.c:67:
/usr/include/openssl/ossl_typ.h:159:29: error: expected ‘)’ before numeric constant
typedef struct X509_name_st X509_NAME;
^
/usr/include/openssl/ossl_typ.h:207:33: error: expected ‘)’ before numeric constant
typedef struct ocsp_response_st OCSP_RESPONSE;
^
make[2]: *** [Makefile:897: iperf_api.lo] Error 1
make[2]: Leaving directory '/iperf-3.6/src'
make[1]: *** [Makefile:665: all] Error 2
make[1]: Leaving directory '/iperf-3.6/src'
make: *** [Makefile:386: all-recursive] Error 1
修改ossl_typ.h文件,添加# include <windows.h>
#ifndef HEADER_OPENSSL_TYPES_H
# define HEADER_OPENSSL_TYPES_H
#include <limits.h>
#ifdef __cplusplus
extern "C" {
#endif
# include <openssl/e_os2.h>
# include <windows.h>
3.2以下版本报错解决
如果编译的是3.2以下版本,如3.1.7,可能会遇到另外两种错误,解决方法如下:
iprintf定义错误:
sed -i 's/iprintf/iiprintf/g' src/*.{c,h}
路径错误:
打开*\src\iperf_api.c文件,查找“XXXXXX”字段,将2667行代码:char buf[] = "/tmp/iperf3.XXXXXX";
,替换为:har buf[ = "./iperf3.XXXXXX";
重新make即可。