mips下交叉编译iperf
因为交叉编译iperf需要用c++编译工具mips-linux-g++,参考下面这篇文章生成交叉编译c++工具mips-linux-g++,如果有相关工具和库文件,请忽略此步。
mips芯片和板子类型为qca953x;
buildroot编译misp-linux-g++工具
http://blog.csdn.net/openswc/article/details/51674108
1.下载iperf源码并解压到相应目录
https://sourceforge.net/projects/iperf
https://iperf.fr/
这里以iperf-2.0.5版本为例;
2.configure及make
cd trunk/apps/iperf-2.0.5
./configure --host=mips-linux --disable-ipv6 --target=mips-linux CC=mips-linux-cc CXX=mips-linux-c++ AR=mips-linux-ar ac_cv_func_malloc_0_nonnull=yes
make
3.build error
(1)Client.cpp
if mips-linux-c++ -DHAVE_CONFIG_H -I. -I. -I.. -I../include -I../include -Wall -O2 -MT Client.o -MD -MP -MF ".deps/Client.Tpo" -c -o Client.o Client.cpp; \
then mv -f ".deps/Client.Tpo" ".deps/Client.Po"; else rm -f ".deps/Client.Tpo"; exit 1; fi
Client.cpp: In member function 'void Client::Connect()':
Client.cpp:419: error: invalid conversion from 'int*' to 'socklen_t*'
Client.cpp:419: error: initializing argument 3 of 'int getsockname(int, sockaddr*, socklen_t*)'
Client.cpp:421: error: invalid conversion from 'int*' to 'socklen_t*'
Client.cpp:421: error: initializing argument 3 of 'int getpeername(int, sockaddr*, socklen_t*)'
修改Client.cpp代码如下:使用(socklen_t *)强制转换下即可
apps/iperf-2.0.5/src$ svn diff -r 2:24 Client.cpp
Index: Client.cpp
===================================================================
--- Client.cpp (revision 2)
+++ Client.cpp (revision 24)
@@ -416,9 +416,9 @@
FAIL_errno( rc == SOCKET_ERROR, "connect", mSettings );
getsockname( mSettings->mSock, (sockaddr*) &mSettings->local,
- &mSettings->size_local );
+ (socklen_t *)&mSettings->size_local );
getpeername( mSettings->mSock, (sockaddr*) &mSettings->peer,
- &mSettings->size_peer );
+ (socklen_t *)&mSettings->size_peer );
} // end Connect
/* -------------------------------------------------------------------
(2)Listener.cpp
then mv -f ".deps/Listener.Tpo" ".deps/Listener.Po"; else rm -f ".deps/Listener.Tpo"; exit 1; fi
Listener.cpp: In member function 'void Listener::Accept(thread_Settings*)':
Listener.cpp:430: error: invalid conversion from 'int*' to 'socklen_t*'
Listener.cpp:430: error: initializing argument 6 of 'ssize_t recvfrom(int, void*, size_t, int, sockaddr*, socklen_t*)'
Listener.cpp:455: error: invalid conversion from 'int*' to 'socklen_t*'
Listener.cpp:455: error: initializing argument 3 of 'int accept(int, sockaddr*, socklen_t*)'
Listener.cpp:463: error: invalid conversion from 'int*' to 'socklen_t*'
Listener.cpp:463: error: initializing argument 3 of 'int getsockname(int, sockaddr*, socklen_t*)'
Listener.cpp: In member function 'void Listener::UDPSingleServer()':
Listener.cpp:495: error: invalid conversion from 'int*' to 'socklen_t*'
Listener.cpp:495: error: initializing argument 6 of 'ssize_t recvfrom(int, void*, size_t, int, sockaddr*, socklen_t*)'
Listener.cpp:523: error: invalid conversion from 'int*' to 'socklen_t*'
Listener.cpp:523: error: initializing argument 3 of 'int getsockname(int, sockaddr*, socklen_t*)'
Index: Listener.cpp
===================================================================
--- Listener.cpp (revision 2)
+++ Listener.cpp (revision 25)
@@ -427,7 +427,7 @@
server->mSock = INVALID_SOCKET;
while ( server->mSock == INVALID_SOCKET ) {
rc = recvfrom( mSettings->mSock, mBuf, mSettings->mBufLen, 0,
- (struct sockaddr*) &server->peer, &server->size_peer );
+ (struct sockaddr*) &server->peer, (socklen_t*)&server->size_peer );
FAIL_errno( rc == SOCKET_ERROR, "recvfrom", mSettings );
Mutex_Lock( &clients_mutex );
@@ -452,7 +452,7 @@
while ( server->mSock == INVALID_SOCKET ) {
// accept a connection
server->mSock = accept( mSettings->mSock,
- (sockaddr*) &server->peer, &server->size_peer );
+ (sockaddr*) &server->peer, (socklen_t*)&server->size_peer );
if ( server->mSock == INVALID_SOCKET && errno == EINTR ) {
continue;
}
@@ -460,7 +460,7 @@
}
server->size_local = sizeof(iperf_sockaddr);
getsockname( server->mSock, (sockaddr*) &server->local,
- &server->size_local );
+ (socklen_t*)&server->size_local );
} // end Accept
void Listener::UDPSingleServer( ) {
@@ -492,7 +492,7 @@
while ( sInterupted == 0) {
server->size_peer = sizeof( iperf_sockaddr );
rc = recvfrom( mSettings->mSock, mBuf, mSettings->mBufLen, 0,
- (struct sockaddr*) &server->peer, &server->size_peer );
+ (struct sockaddr*) &server->peer, (socklen_t*)&server->size_peer );
WARN_errno( rc == SOCKET_ERROR, "recvfrom" );
if ( rc == SOCKET_ERROR ) {
return;
@@ -520,7 +520,7 @@
Mutex_Unlock( &groupCond );
server->size_local = sizeof(iperf_sockaddr);
getsockname( mSettings->mSock, (sockaddr*) &server->local,
- &server->size_local );
+ (socklen_t*)&server->size_local );
break;
}
} else {
Dynamic section at offset 0x180 contains 29 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libstdc++.so.6]
0x00000001 (NEEDED) Shared library: [libm.so.0]
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x00000001 (NEEDED) Shared library: [libpthread.so.0]
0x00000001 (NEEDED) Shared library: [libc.so.0]
0x0000000c (INIT) 0x402b88
0x0000000d (FINI) 0x40f570
trunk\build\buildroot-2009.08\build_mips\staging_dir\usr\mips-linux-uclibc\lib
Usage: iperf [-s|-c host] [options]
Try `iperf --help' for more information.
库文件路径
将这5个库文件导入到将板子/lib目录下,如果/lib目录下已有相应的库文件,则忽略。
[libstdc++.so.6];[libm.so.0];[libgcc_s.so.1]; [libpthread.so.0];[libc.so.0]
trunk/build/buildroot-2009.08/build_mips/staging_dir/usr/mips-linux-uclibc/lib$ ls -l
total 14808
lrwxrwxrwx 1 root root 13 Jun 6 17:26 libgcc_s.so -> libgcc_s.so.1
-rw-r--r-- 1 root root 1561941 Jun 6 17:26 libgcc_s.so.1
lrwxrwxrwx 1 root root 19 Jun 6 17:26 libstdc++.so.6 -> libstdc++.so.6.0.10
-rwxr-xr-x 1 root root 3802368 Jun 6 17:26 libstdc++.so.6.0.10
trunk/build/buildroot-2009.08/build_mips/staging_dir/lib$ ls -l
lrwxrwxrwx 1 root root 19 Jun 6 17:17 libc.so.0 -> libuClibc-0.9.30.so
-rw-r--r-- 1 root root 107236 Jun 6 17:18 libm-0.9.30.so
lrwxrwxrwx 1 root root 14 Jun 6 17:17 libm.so.0 -> libm-0.9.30.so
-rw-r--r-- 1 root root 79464 Jun 6 17:18 libpthread-0.9.30.so
lrwxrwxrwx 1 root root 20 Jun 6 17:18 libpthread.so.0 -> libpthread-0.9.30.so
-rw-r--r-- 1 root root 435956 Jun 6 17:18 libuClibc-0.9.30.so
trunk/build/buildroot-2009.08/build_mips/staging_dir/usr/lib$ ls -l
lrwxrwxrwx 1 root root 19 Jun 6 17:18 libm.so -> ../../lib/libm.so.0
lrwxrwxrwx 1 root root 25 Jun 6 17:18 libpthread.so -> ../../lib/libpthread.so.0
$ ls trunk/rootfs-ap143.build/lib/ -l
-rwxr-xr-x 1 root root 22604 May 28 17:44 ld-uClibc-0.9.30.so
lrwxrwxrwx 1 root root 19 May 28 17:44 ld-uClibc.so.0 -> ld-uClibc-0.9.30.so
-rw-rw-r-- 1 root root 472516 May 28 17:45 libacfg.a
-rw-r--r-- 1 root root 11288 May 28 17:44 libcrypt-0.9.30.so
lrwxrwxrwx 1 root root 18 May 28 17:44 libcrypt.so.0 -> libcrypt-0.9.30.so
lrwxrwxrwx 1 root root 19 May 28 17:44 libc.so.0 -> libuClibc-0.9.30.so
-rw-r--r-- 1 root root 9504 May 28 17:44 libdl-0.9.30.so
lrwxrwxrwx 1 root root 15 May 28 17:44 libdl.so.0 -> libdl-0.9.30.so
lrwxrwxrwx 1 root root 13 May 28 17:44 libgcc_s.so -> libgcc_s.so.1
-rw-r--r-- 1 root root 1554941 May 28 17:44 libgcc_s.so.1
-rwxrwxr-x 1 root root 73483 May 28 17:45 libiw.so.29
-rw-r--r-- 1 root root 107236 May 28 17:44 libm-0.9.30.so
lrwxrwxrwx 1 root root 14 May 28 17:44 libm.so.0 -> libm-0.9.30.so
-rw-r--r-- 1 root root 1712 May 28 17:44 libnsl-0.9.30.so
lrwxrwxrwx 1 root root 16 May 28 17:44 libnsl.so.0 -> libnsl-0.9.30.so
-rw-r--r-- 1 root root 79464 May 28 17:44 libpthread-0.9.30.so
lrwxrwxrwx 1 root root 20 May 28 17:44 libpthread.so.0 -> libpthread-0.9.30.so
-rw-r--r-- 1 root root 1716 May 28 17:44 libresolv-0.9.30.so
lrwxrwxrwx 1 root root 19 May 28 17:44 libresolv.so.0 -> libresolv-0.9.30.so
-rw-r--r-- 1 root root 4652 May 28 17:44 librt-0.9.30.so
lrwxrwxrwx 1 root root 15 May 28 17:44 librt.so.0 -> librt-0.9.30.so
-rw-r--r-- 1 root root 435956 May 28 17:44 libuClibc-0.9.30.so
-rw-r--r-- 1 root root 4900 May 28 17:44 libutil-0.9.30.so
lrwxrwxrwx 1 root root 17 May 28 17:44 libutil.so.0 -> libutil-0.9.30.so
drwxrwxr-x 4 root root 4096 May 28 17:44 modules
qca953x board
/lib # ls -l
-rwxr-xr-x 1 root root 20704 May 28 2017 ld-uClibc-0.9.30.so
lrwxrwxrwx 1 root root 19 May 28 2017 ld-uClibc.so.0 -> ld-uClibc-0.9.30.so
lrwxrwxrwx 1 root root 19 May 28 2017 libc.so.0 -> libuClibc-0.9.30.so
-rw-r--r-- 1 root root 11288 May 28 2017 libcrypt-0.9.30.so
lrwxrwxrwx 1 root root 18 May 28 2017 libcrypt.so.0 -> libcrypt-0.9.30.so
-rw-r--r-- 1 root root 9504 May 28 2017 libdl-0.9.30.so
lrwxrwxrwx 1 root root 15 May 28 2017 libdl.so.0 -> libdl-0.9.30.so
lrwxrwxrwx 1 root root 13 May 28 2017 libgcc_s.so -> libgcc_s.so.1
-rw-r--r-- 1 root root 1554941 May 28 2017 libgcc_s.so.1
-rwxr-xr-x 1 root root 30211 May 28 2017 libiw.so.29
-rw-r--r-- 1 root root 107236 May 28 2017 libm-0.9.30.so
lrwxrwxrwx 1 root root 14 May 28 2017 libm.so.0 -> libm-0.9.30.so
-rw-r--r-- 1 root root 1712 May 28 2017 libnsl-0.9.30.so
lrwxrwxrwx 1 root root 16 May 28 2017 libnsl.so.0 -> libnsl-0.9.30.so
-rw-r--r-- 1 root root 79464 May 28 2017 libpthread-0.9.30.so
lrwxrwxrwx 1 root root 20 May 28 2017 libpthread.so.0 -> libpthread-0.9.30.so
-rw-r--r-- 1 root root 1716 May 28 2017 libresolv-0.9.30.so
lrwxrwxrwx 1 root root 19 May 28 2017 libresolv.so.0 -> libresolv-0.9.30.so
-rw-r--r-- 1 root root 4652 May 28 2017 librt-0.9.30.so
lrwxrwxrwx 1 root root 15 May 28 2017 librt.so.0 -> librt-0.9.30.so
-rw-r--r-- 1 root root 435956 May 28 2017 libuClibc-0.9.30.so
-rw-r--r-- 1 root root 4900 May 28 2017 libutil-0.9.30.so
lrwxrwxrwx 1 root root 17 May 28 2017 libutil.so.0 -> libutil-0.9.30.so
drwxr-xr-x 4 root root 0 May 28 2017 modules
/lib #