updateing / minieap

可扩展的 802.1x 客户端,带有锐捷 v3 (v4) 算法插件支持
GNU General Public License v3.0
514 stars 93 forks source link

关于交叉编译,有几个问题想请教.. #6

Closed BlingRbt closed 7 years ago

BlingRbt commented 7 years ago

1.关于交叉编译配置文件该怎么写? 2.我没有SDK环境是否无法交叉编译? 3.无SDK 但有完整源码是否可以交叉编译?(源码已编译过不少固件) 4.能否直接加入MakeMenuconfig里面自带设置呢? (我尝试直接make可以出来一个文件,自己交叉编译 出错误显示无法找到命令是不是没有SDK的缘故....第一次尝试交叉编译 还请见谅)

updateing commented 7 years ago
  1. config.mk 中最底下有交叉编译的配置实例。我自己的用法是先export PATH来包含工具链的bin文件夹,然后把32行到37行解开注释即可。当然libiconv是预先编译的,路径要改。

    要注意的是工具链里有没有实现ifaddrs(经常是头文件里有但无法链接)。没有的话就得自己去寻找一份ifaddrs的实现放到util/ifaddrs和include里面去,这在README里提过了。

    如果工具链里面有ifaddrs,那直接保持PLUGIN_MODULES += ifaddrs注释就好了。

    2 & 3. 如果你是说OpenWrt / LEDE,那么源码编译出来以后staging_dir下面就有工具链……

  2. 尝试过可以,但考虑到OpenWrt和LEDE里面的libiconv包括-full版本在内都不完整,直接用会导致segfault,所以没太大意义。

BlingRbt commented 7 years ago

还想请教一下... libiconv交叉编译命令怎么写.... 查了半天... make CC=mipsel-openwrt-linux-gcc AR=mipsel-openwrt-linux-ar RANLIB=mipsel-openwrt-linux-ranlib CXX=mipsel-linux-g++这个对吗 我编译显示 .libs/localcharset.o: error adding symbols: File in wrong format collect2: error: ld returned 1 exit status Makefile:59: recipe for target 'libcharset.la' failed make[2]: [libcharset.la] Error 1 make[2]: Leaving directory '/home/rabbit/libiconv-1.14/libcharset/lib' Makefile:34: recipe for target 'all' failed make[1]: [all] Error 2 make[1]: Leaving directory '/home/rabbit/libiconv-1.14/libcharset' Makefile:42: recipe for target 'lib/localcharset.h' failed make: *** [lib/localcharset.h] Error 2 新人...实在不会交叉编译....

updateing commented 7 years ago
cd /path/to/libiconv
export PATH=$PATH:/path/to/openwrt/toolchain/bin
./configure --host=mips-openwrt-linux --enable-static=yes --enable-shared=yes --disable-nls
make

已经编译过的话要先make clean.

configure的情况下就不要直接指定CC等变量了,很容易指定不全,还麻烦。让configure做好它自己的事就行。

以上代码来自 https://github.com/updateing/mentohust-v4-proxy/blob/master/BuildGuide.md#building-for-openwrt-1404--mips

BlingRbt commented 7 years ago

大大 我make之后找不到文件了.... 虽然成功编译,但找不到libiconv.a文件 我之前安装到ubuntu了 用的sudo make install....有没有影响?

updateing commented 7 years ago

不install的话文件藏的比较深,可以用find命令来找。也可以在configure的时候加--prefix参数,装到专门的位置,就可以执行make install而不需要sudo。

如果是交叉编译再sudo make install的话,可能让系统里原本的libiconv被mips版本的覆盖,导致崩溃。可以用file检查一下。真被覆盖了的话重新用主机的工具链编译安装就是了。或者直接删了然后从包管理器重装。

没有足够的把握会发生什么的话,尽量不要做make install,特别是sudo make install。本身是通过包管理器来管理的话,就更是如此了。

BlingRbt commented 7 years ago

大大 我之前是直接

Linux下libiconv库的安装和使用: 1.编译安装libiconv库 包的下载页面http://www.gnu.org/software/libiconv/ $ ./configure --prefix=/usr/loca $ make $ make install 2.在/usr/local/lib/目录下拷备需要的库文件libcharset.so.1, libiconv.so.2。 按照这个来执行的 后来才发现 这个是系统的库 而不是我要的库 (然后发现make install执行不了 我就执行了sudo.....

现在按着上面的做法 能编译成功 但是却找不到.a文件了 怎么破.... 我全局搜索也没找到...找到还是之前安装在/usr/local里的libiconv.a

好纠结...在原文里$ROOT/lib/.libs这个路径我没有...

BlingRbt commented 7 years ago

大大 我编译出来了 找到了 原来就在这个文件夹下/libiconv/lib/.libs 可是在minieap里make却出错了 rabbit@ubuntu:~/openwrt/package/minieap$ make mipsel-openwrt-linux-gcc -o minieap \ -T minieap_init_func.lds -static \ \ packet_plugin/printer/packet_plugin_printer.o packet_plugin/rjv3//packet_plugin_rjv3.o packet_plugin/rjv3//packet_plugin_rjv3_priv.o packet_plugin/rjv3//packet_plugin_rjv3_keepalive.o packet_plugin/rjv3//packet_plugin_rjv3_prop.o packet_plugin/rjv3/rjv3_hashes/rjtiger.o packet_plugin/rjv3/rjv3_hashes/rjwhirlpool.o packet_plugin/rjv3/rjv3_hashes/byte_order.o packet_plugin/rjv3/rjv3_hashes/rjripemd128.o packet_plugin/rjv3/rjv3_hashes/rjsha1.o packet_plugin/rjv3/rjv3_hashes/rjtiger_sbox.o packet_plugin/rjv3/rjv3_hashes/rjwhirlpool_sbox.o packet_plugin/rjv3/rjv3_hashes/rjmd5.o packet_plugin/rjv3/rjv3_hashes/checkV4.o if_impl/sockraw/if_impl_sockraw.o util//linkedlist.o util//sched_alarm.o util//logging.o util//misc.o util//packet_util.o util//conf_parser.o util//net_util.o .//packet_builder.o .//config.o .//eap_state_machine.o .//md5.o .//minieap.o if_impl//if_impl.o packet_plugin//packet_plugin.o \ /home/rabbit/openwrt/staging_dir/libiconv.a /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: packet_plugin/printer/packet_plugin_printer.o: Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: packet_plugin/printer/packet_plugin_printer.o: Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: packet_plugin/printer/packet_plugin_printer.o: Relocations in generic ELF (EM: 62) packet_plugin/printer/packet_plugin_printer.o: error adding symbols: File in wrong format collect2: error: ld returned 1 exit status Makefile:40: recipe for target 'minieap' failed make: *** [minieap] Error 1 这是什么错误呢?

updateing commented 7 years ago

在这里也要make clean。没有解决问题的话,用find-delete删除所有.o文件,

BlingRbt commented 7 years ago

大大看一下我的配置有没有错误?

Example for cross-compiling

CC := mipsel-openwrt-linux-gcc ENABLE_ICONV := true CUSTOM_CFLAGS += -I/home/libiconv-1.14/include CUSTOM_LIBS += /home/rabbit/openwrt/staging_dir/libiconv.a PLUGIN_MODULES += ifaddrs STATIC_BUILD := true

确实 我makeclean后出错了....

rabbit@ubuntu:~/openwrt/package/minieap$ make mipsel-openwrt-linux-gcc -Ipacket_plugin/printer/ -Iinclude -I/home/libiconv-1.14/include -Wall -D_GNU_SOURCE -DENABLE_ICONV packet_plugin/printer/packet_plugin_printer.c -c -o packet_plugin/printer/packet_plugin_printer.o mipsel-openwrt-linux-gcc -Ipacket_plugin/rjv3/rjv3_hashes -Ipacket_plugin/rjv3/ -Iinclude -I/home/libiconv-1.14/include -Wall -D_GNU_SOURCE -DENABLE_ICONV packet_plugin/rjv3//packet_plugin_rjv3.c -c -o packet_plugin/rjv3//packet_plugin_rjv3.o packet_plugin/rjv3//packet_plugin_rjv3.c: In function 'rjv3_save_one_prop': packet_plugin/rjv3//packet_plugin_rjv3.c:295:5: error: 'for' loop initial declarations are only allowed in C99 mode for (int i = 0; i < PROP_TO_CONTENT_SIZE(TO_RJ_PROP(prop)); i++) { ^ packet_plugin/rjv3//packet_plugin_rjv3.c:295:5: note: use option -std=c99 or -std=gnu99 to compile your code /home/rabbit/openwrt/package/minieap/append.mk:22: recipe for target 'packet_plugin/rjv3//packet_plugin_rjv3.o' failed make: *** [packet_plugin/rjv3//packet_plugin_rjv3.o] Error 1

是我哪一步出问题了?

updateing commented 7 years ago
--- a/packet_plugin/rjv3/packet_plugin_rjv3.c
+++ b/packet_plugin/rjv3/packet_plugin_rjv3.c
@@ -292,7 +292,8 @@ static void rjv3_save_one_prop(void* prop, void* is_mod) {
     curr_pos += 2;
     *curr_pos++ = ':';

-    for (int i = 0; i < PROP_TO_CONTENT_SIZE(TO_RJ_PROP(prop)); i++) {
+    int i;
+    for (i = 0; i < PROP_TO_CONTENT_SIZE(TO_RJ_PROP(prop)); i++) {
         hex2char(TO_RJ_PROP(prop)->content[i], curr_pos);
         curr_pos += 2;
     }
BlingRbt commented 7 years ago

我gitpull了一下发现没有新的-=- 然后我看了一下其他branch发现有不同 然后我照着改了...又出现了个新问题-=-

mipsel-openwrt-linux-gcc -Iutil/ -Iinclude -I/home/libiconv-1.14/include -Wall -D_GNU_SOURCE -DENABLE_ICONV util//misc.c -c -o util//misc.o util//misc.c:15:19: fatal error: iconv.h: No such file or directory

include

^ compilation terminated. /home/rabbit/openwrt/package/minieap/append.mk:22: recipe for target 'util//misc.o' failed make: *** [util//misc.o] Error 1

这是啥问题呢? 好像是iconv.h未被包含吧....去append.mk里修改?

updateing commented 7 years ago

我的意思是照着刚才那个patch改,就是把变量声明移到外面。(此外你该升级编译器了,GCC 5.1就已经把默认的标准改成gnu11了)

其他分支都是旧代码,对比commit log就知道了。切回master然后重新配置config.mk吧。

BlingRbt commented 7 years ago

大大 我改了回来 把变量提出来了 (295行开始)

int i; for (i = 0; i < PROP_TO_CONTENT_SIZE(TO_RJ_PROP(prop)); i++) { hex2char(TO_RJ_PROP(prop)->content[i], curr_pos); curr_pos += 2; }

但是还是这个错误

mipsel-openwrt-linux-gcc -Iutil/ -Iinclude -I/home/libiconv-1.14/include -Wall -D_GNU_SOURCE -DENABLE_ICONV util//misc.c -c -o util//misc.o util//misc.c:15:19: fatal error: iconv.h: No such file or directory

include

怎么破?

updateing commented 7 years ago

CUSTOM_CFLAGS += -I/home/libiconv-1.14/include

/home/libiconv-1.14/include 这个路径存在吗

BlingRbt commented 7 years ago

大大 我重新make clean后 重新编译发现可能是 libiconv.a 的问题

    /home/rabbit/openwrt/staging_dir/libiconv.a

/home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: /home/rabbit/openwrt/staging_dir/libiconv.a(iconv.o): Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: /home/rabbit/openwrt/staging_dir/libiconv.a(iconv.o): Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: /home/rabbit/openwrt/staging_dir/libiconv.a(iconv.o): Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: /home/rabbit/openwrt/staging_dir/libiconv.a(iconv.o): Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: /home/rabbit/openwrt/staging_dir/libiconv.a(iconv.o): Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: /home/rabbit/openwrt/staging_dir/libiconv.a(iconv.o): Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: /home/rabbit/openwrt/staging_dir/libiconv.a(iconv.o): Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/libiconv.a: error adding symbols: File in wrong format collect2: error: ld returned 1 exit status Makefile:40: recipe for target 'minieap' failed make: *** [minieap] Error 1

大大能发一份mispel的libiconv.a嘛? 我这编译出来的好像不能用...

updateing commented 7 years ago

这说明libiconv交叉编译失败,实际编译用的是主机的工具链。检查编译的时候PATH对不对,手动执行--host内容-gcc(比如--host是mipsel-openwrt-linux,那就执行mipsel-openwrt-linux-gcc)看有没有。最后,还有config.log可以看。

BlingRbt commented 7 years ago

大大 交叉编译的时候出现这

./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function)

我直接在stdio.h将1010行的get改成fget能过编译

然后我试着编译了 十几遍....在minieap里make总是不成功

/home/rabbit/openwrt/staging_dir/libiconv.a /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: /home/rabbit/openwrt/staging_dir/libiconv.a(iconv.o): Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: /home/rabbit/openwrt/staging_dir/libiconv.a(iconv.o): Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: /home/rabbit/openwrt/staging_dir/libiconv.a(iconv.o): Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: /home/rabbit/openwrt/staging_dir/libiconv.a(iconv.o): Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: /home/rabbit/openwrt/staging_dir/libiconv.a(iconv.o): Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: /home/rabbit/openwrt/staging_dir/libiconv.a(iconv.o): Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: /home/rabbit/openwrt/staging_dir/libiconv.a(iconv.o): Relocations in generic ELF (EM: 62) /home/rabbit/openwrt/staging_dir/libiconv.a: error adding symbols: File in wrong format collect2: error: ld returned 1 exit status Makefile:40: recipe for target 'minieap' failed make: *** [minieap] Error 1

这个怎么破....我已经要疯了...

BlingRbt commented 7 years ago

大大 解决了

./configure --host=mipsel-openwrt-linux --enable-shared --enable-static --prefix=/usr/local/mipsel/libiconv

使用这个参数编译出来的是1.4M 原来的是1.6M minieap里没有错误信息是不是就是编译成功了? 生成的是可执行文件 没有后缀 直接拷贝到路由器就能使用对吗?

updateing commented 7 years ago

应该能用了,记得chmod +x.

BlingRbt commented 7 years ago

哦哦 chmod +x minieap? 这个命令是去除执行权限? 我直接拷出来了 没事吧....

对了 大大 有没有想着弄个Luci呢.........

updateing commented 7 years ago

+x难道不是添加执行权限吗…… 这又不会有什么后果,随便搞 考完研可以考虑加luci,不过我个人更喜欢命令行,minieap的命令行还没复杂到需要图形界面辅助的程度

BlingRbt commented 7 years ago

额....我从来还没有这样用过...我都是右键属性里加...(当然路由器里还是要chmod.....

哈哈 我还是喜欢图形界面 感觉很直观嘛.....

加油考研 考完我也学学写luci....

sequencer commented 7 years ago

可以把写成openwrt的一个服务 luci好处在于web界面就能直接管理了 其实也挺简单的 等conf的版本出了我去这一个吧 //你政治背完了嘛

BlingRbt commented 7 years ago

(可以类似S~S-=- app-s~s luci-app-s~s 这样可以直接集成 感觉会更方便

(啥时候LEDE才能有个稳定版....

BlingRbt commented 7 years ago

哦对 忘了说了 有luci的好处是 会有配置文件 直接读取就好了 而不用输命令了....直接运行 默认读取配置 这样是不是更方便一点呢?

updateing commented 7 years ago

我自己目前是加在rc. local里在用,radvd之类做了服务。

带conf的版本几天前就已经push了(用-w会自己生成一个),日常在跑,不过所有的参数都还是在命令行上给定了(没改)。

LEDE在ipq806x已经很稳定了,起码我的EA8500带IPv6公网+NAT且同时挂一天种子都不会有问题。

BlingRbt commented 7 years ago

EA8500。。。。。。。。。买不起系列......................

updateing commented 7 years ago

R6220改SPI刷LEDE借给同学用也没听他说因为不稳定而重启啊……自己尝试一下就知道了。

sequencer commented 7 years ago

你的8500 ac稳定么 我一直听说openwrt的ac不稳定 不敢买

updateing commented 7 years ago

ath10k,非CT版本,157信道 80MHz,笔记本是BCM94352HMB,iperf稳定速度一般大概在550Mbps,连续多次测试时可能会有400Mbps到680Mbps的变化(单次测试中基本稳定,但多次测试的结果有较大差异,680Mbps稳定速度甚至超过官方固件)

笔记本和手机都是日常连ac的,没感觉有什么问题。

updateing commented 7 years ago

已经没问题了的样子……

sequencer commented 7 years ago

感觉还是有个问题 同@BlingRabbit 的错误相同

mips-openwrt-linux-gcc  -Iutil/ -Iinclude  /usr/share/openwrt_dev/package/libiconv-1.14/include/ -Wall -D_GNU_SOURCE -DENABLE_ICONV  util//misc.c -c -o util//misc.o
util//misc.c:16:19: fatal error: iconv.h: No such file or directory
 #include <iconv.h>
                   ^
compilation terminated

/usr/share/openwrt_dev/package/libiconv-1.14/include/目录下存在iconv.h libiconv确定用openwrt的工具链编译

# config.mk
#### Choose/Add your modules here ####
PLUGIN_MODULES := \
        packet_plugin_printer \
        packet_plugin_rjv3

# Linux
PLUGIN_MODULES += if_impl_sockraw

# macOS / BSD
# PLUGIN_MODULES += if_impl_bpf

# Other OS
# PLUGIN_MODULES += if_impl_libpcap

# This implementation is not included in the code.
# If you need it, add it yourselves.
# PLUGIN_MODULES += ifaddrs

ENABLE_DEBUG := false
ENABLE_ICONV := true
STATIC_BUILD := false

# If your platform has iconv_* integrated into libc, change to false
# Affects dynamic linking
LIBICONV_STANDALONE := false

CUSTOM_CFLAGS :=
CUSTOM_LDFLAGS :=
CUSTOM_LIBS :=

# Example for cross-compiling
 CC := mips-openwrt-linux-gcc
 ENABLE_ICONV := true
 CUSTOM_CFLAGS += /usr/share/openwrt_dev/package/libiconv-1.14/include/
 CUSTOM_LIBS += /usr/share/openwrt_dev/package/libiconv-1.14/lib/.libs/libiconv.a
 PLUGIN_MODULES += ifaddrs
 STATIC_BUILD := true

目测@BlingRabbit是引入动态库解决的吧?

updateing commented 7 years ago

注意是CUSTOM_CFLAGS,前面要有-I才是完整的用于指定头文件路径的CFLAGS

CUSTOM_CFLAGS += -I/usr/share/openwrt_dev/package/libiconv-1.14/include/
sequencer commented 7 years ago

好吧 原来如此 (:з」∠)