我正在尝试使用minGW / MSYS在Windows上编译iPerf。当我运行./configure时,一切看起来都很好:

$ ./configure
checking for a BSD-compatible install... /bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for style of include used by make... GNU
checking dependency style of g++... gcc3
checking for gcc... gcc
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking for library containing strerror... none required
checking whether make sets $(MAKE)... (cached) yes
checking for ranlib... ranlib
checking build system type... i686-pc-mingw32
checking host system type... i686-pc-mingw32
checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... no
checking whether pthreads work with -Kthread... no
checking whether pthreads work with -kthread... no
checking for the pthreads library -llthread... no
checking whether pthreads work with -pthread... no
checking whether pthreads work with -pthreads... no
checking whether pthreads work with -mthreads... no
checking for the pthreads library -lpthread... no
checking whether pthreads work with --thread-safe... no
checking whether pthreads work with -mt... no
checking for pthread-config... no
checking for gethostbyname... no
checking for gethostbyname in -lnsl... no
checking for socket... no
checking for socket in -lsocket... no
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking arpa/inet.h usability... no
checking arpa/inet.h presence... no
checking for arpa/inet.h... no
checking libintl.h usability... no
checking libintl.h presence... no
checking for libintl.h... no
checking netdb.h usability... no
checking netdb.h presence... no
checking for netdb.h... no
checking netinet/in.h usability... no
checking netinet/in.h presence... no
checking for netinet/in.h... no
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for strings.h... (cached) yes
checking sys/socket.h usability... no
checking sys/socket.h presence... no
checking for sys/socket.h... no
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking syslog.h usability... no
checking syslog.h presence... no
checking for syslog.h... no
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking for size_t... yes
checking for ssize_t... yes
checking whether time.h and sys/time.h may both be included... yes
checking whether struct tm is in sys/time.h or time.h... time.h
checking for stdint types... stdint.h (shortcircuit)
make use of stdint.h in include/iperf-int.h (assuming C99 compatible system)
checking 3rd argument of accept...
checking for pid_t... yes
checking vfork.h usability... no
checking vfork.h presence... no
checking for vfork.h... no
checking for fork... no
checking for vfork... no
checking for stdlib.h... (cached) yes
checking for GNU libc compatible malloc... yes
checking for working memcmp... yes
checking sys/select.h usability... no
checking sys/select.h presence... no
checking for sys/select.h... no
checking for sys/socket.h... (cached) no
checking types of arguments for select... int,int *,struct timeval *
checking return type of signal handlers... void
checking for strftime... yes
checking for vprintf... yes
checking for _doprnt... no
checking for atexit... yes
checking for gettimeofday... yes
checking for memset... yes
checking for pthread_cancel... no
checking for select... no
checking for strchr... yes
checking for strerror... yes
checking for strtol... yes
checking for usleep... yes
checking for snprintf... yes
checking for inet_pton... no
checking for inet_ntop... no
checking for gettimeofday... (cached) yes
checking *printf() support for %lld... yes
checking size of bool... 0
checking if true is defined... yes
checking whether byte ordering is bigendian... no
checking for struct ip_mreq... no
checking whether IP_ADD_MEMBERSHIP is declared... no
checking for multicast support... no
checking for struct sockaddr_storage... no
checking for struct sockaddr_in6... no
checking whether AF_INET6 is declared... no
checking for IPv6 headers and structures... no
checking whether make is GNU make... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating compat/Makefile
config.status: creating doc/Makefile
config.status: creating include/Makefile
config.status: creating src/Makefile
config.status: creating man/Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
config.status: executing include/iperf-int.h commands
config.status: creating include/iperf-int.h : _IPERF_INCLUDE_IPERF_INT_H
config.status: include/iperf-int.h is unchanged


当我尝试制作程序时,即使在./configure中声称它找到了该功能,但gettimeofday函数还是出现了错误。

$ make
make  all-recursive
make[1]: Entering directory `/c/users/c_bhaskv/desktop/iperf-2.0.5'
Making all in compat
make[2]: Entering directory `/c/users/c_bhaskv/desktop/iperf-2.0.5/compat'
if g++ -DHAVE_CONFIG_H -I. -I. -I..  -I../include -I../include  -Wall -O2  -MT delay.o -MD -MP -MF ".deps/delay.Tpo" -c -o delay.o delay.cpp; \
        then mv -f ".deps/delay.Tpo" ".deps/delay.Po"; else rm -f ".deps/delay.Tpo"; exit 1; fi
In file included from ../include/Timestamp.hpp:63:0,
                 from delay.cpp:53:
../include/headers.h:93:0: warning: "_WIN32_WINNT" redefined [enabled by default]
     #define _WIN32_WINNT 0x0400 /* use (at least) WinNT 4.0 API */
 ^
In file included from c:\mingw\include\_mingw.h:35:0,
                 from c:\mingw\include\stdlib.h:27,
                 from ../include/headers.h:78,
                 from ../include/Timestamp.hpp:63,
                 from delay.cpp:53:
c:\mingw\include\sdkddkver.h:154:0: note: this is the location of the previous definition
 #    define _WIN32_WINNT _WIN32_WINNT_WIN2K
 ^
In file included from delay.cpp:53:0:
../include/Timestamp.hpp: In member function 'void Timestamp::setnow()':
../include/Timestamp.hpp:93:36: error: 'gettimeofday' was not declared in this scope
         gettimeofday( &mTime, NULL );
                                    ^
delay.cpp: In function 'void delay_loop(long unsigned int)':
delay.cpp:64:21: error: aggregate 'delay_loop(long unsigned int)::timespec requested' has incomplete type and cannot be defined
     struct timespec requested, remaining;
                     ^
delay.cpp:64:32: error: aggregate 'delay_loop(long unsigned int)::timespec remaining' has incomplete type and cannot be defined
     struct timespec requested, remaining;
                                ^
delay.cpp:69:44: error: 'nanosleep' was not declared in this scope
     while (nanosleep(&requested, &remaining) == -1)
                                            ^


关于如何解决这些错误的任何想法?

谢谢

最佳答案

注意:

checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes


然后,如果它说:

error: 'gettimeofday' was not declared in this scope


那么很明显,库本身的标题出了点问题,即sys/time.h根本没有正确包含。快速浏览到<iperf-dir>/include/headers.h并快速浏览它会发现,当我们在Windows上时,即sys/time.h块中不包含#ifdef WIN32,而对于Unix块(在#else中)确实包含了。结果,您要做的就是添加:

#include <sys/time.h>


例如,在第91行的<iperf-dir>/include/headers.h中。

尽管这可以解决您当前的问题,但是您稍后会在编译过程中遇到一些无法编译的代码(即,编写有误),但仍然会失败。此外,坦率地说,该库是针对Windows可移植性而设计的。该代码看起来非常古老和丑陋,因此不编译就不足为奇了。您可能对iperf 3感到更幸运,因为它们可能提高了库的质量及其可移植性问题。

08-04 02:21