编译hostapd时,出现错误:/usr/bin/ld: cannot find -lnl
book@ubuntu:/work/project/wifi/04.hostapd/hostapd-2.0/hostapd$ make
/usr/bin/ld: cannot find -lnl
collect2: ld returned 1 exit status
make: *** [hostapd] Error 1
问题原因是,没有找到 nl 库 !
src/drivers/drivers.mak:31: DRV_LIBS += -lnl-3
src/drivers/drivers.mak:32: DRV_LIBS += -lnl-genl-3
src/drivers/drivers.mak:36: DRV_LIBS += -lnl-tiny
src/drivers/drivers.mak:38: DRV_LIBS += -lnl
src/drivers/drivers.mak:42: DRV_LIBS += -lnl-genl
src/drivers/drivers.mak:148: DRV_LIBS += -lnl-3
src/drivers/drivers.mak:149: DRV_LIBS += -lnl-genl-3
src/drivers/drivers.mak:150: DRV_LIBS += -lnl-route-3
src/drivers/drivers.mak:154: DRV_LIBS += -lnl-tiny
src/drivers/drivers.mak:156: DRV_LIBS += -lnl
src/drivers/drivers.mak:160: DRV_LIBS += -lnl-genl
src/drivers/drivers.mak:161: DRV_LIBS += -lnl-route
src/drivers/drivers.mk:31: DRV_LIBS += -lnl-3
src/drivers/drivers.mk:32: DRV_LIBS += -lnl-genl-3
src/drivers/drivers.mk:36: DRV_LIBS += -lnl-tiny
src/drivers/drivers.mk:38: DRV_LIBS += -lnl
src/drivers/drivers.mk:42: DRV_LIBS += -lnl-genl
src/drivers/drivers.mk:152: DRV_LIBS += -lnl-3
src/drivers/drivers.mk:153: DRV_LIBS += -lnl-genl-3
src/drivers/drivers.mk:154: DRV_LIBS += -lnl-route-3
src/drivers/drivers.mk:158: DRV_LIBS += -lnl-tiny
src/drivers/drivers.mk:160: DRV_LIBS += -lnl
src/drivers/drivers.mk:164: DRV_LIBS += -lnl-genl
src/drivers/drivers.mk:165: DRV_LIBS += -lnl-route
然后,我们查看交叉编译库里 有没有 nl 的库
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib
然后,打开这个文件。
vi src/drivers/drivers.mk +31
发现下面这几句。
ifdef CONFIG_LIBNL32
DRV_LIBS += -lnl-3
DRV_LIBS += -lnl-genl-3
DRV_CFLAGS += -DCONFIG_LIBNL20 -I/usr/include/libnl3
那么我们只需要,在配置文件.config里,加 CONFIG_LIBNL32 = y 就可以了。
/usr/bin/ld: cannot find -lnl
collect2: ld returned 1 exit status
make: *** [hostapd] Error 1
问题原因是,没有找到 nl 库 !
然后我搜索 这个 nl 库是在哪儿被使用的:
book@ubuntu:/work/project/wifi/04.hostapd/hostapd-2.0$ grep "\-lnl" * -nRsrc/drivers/drivers.mak:31: DRV_LIBS += -lnl-3
src/drivers/drivers.mak:32: DRV_LIBS += -lnl-genl-3
src/drivers/drivers.mak:36: DRV_LIBS += -lnl-tiny
src/drivers/drivers.mak:38: DRV_LIBS += -lnl
src/drivers/drivers.mak:42: DRV_LIBS += -lnl-genl
src/drivers/drivers.mak:148: DRV_LIBS += -lnl-3
src/drivers/drivers.mak:149: DRV_LIBS += -lnl-genl-3
src/drivers/drivers.mak:150: DRV_LIBS += -lnl-route-3
src/drivers/drivers.mak:154: DRV_LIBS += -lnl-tiny
src/drivers/drivers.mak:156: DRV_LIBS += -lnl
src/drivers/drivers.mak:160: DRV_LIBS += -lnl-genl
src/drivers/drivers.mak:161: DRV_LIBS += -lnl-route
src/drivers/drivers.mk:31: DRV_LIBS += -lnl-3
src/drivers/drivers.mk:32: DRV_LIBS += -lnl-genl-3
src/drivers/drivers.mk:36: DRV_LIBS += -lnl-tiny
src/drivers/drivers.mk:38: DRV_LIBS += -lnl
src/drivers/drivers.mk:42: DRV_LIBS += -lnl-genl
src/drivers/drivers.mk:152: DRV_LIBS += -lnl-3
src/drivers/drivers.mk:153: DRV_LIBS += -lnl-genl-3
src/drivers/drivers.mk:154: DRV_LIBS += -lnl-route-3
src/drivers/drivers.mk:158: DRV_LIBS += -lnl-tiny
src/drivers/drivers.mk:160: DRV_LIBS += -lnl
src/drivers/drivers.mk:164: DRV_LIBS += -lnl-genl
src/drivers/drivers.mk:165: DRV_LIBS += -lnl-route
然后,我们查看交叉编译库里 有没有 nl 的库
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib
然后,发现里面有这个库。
book@ubuntu:/work/project/wifi/04.hostapd/hostapd-2.0$ ls /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib engines libnl libnsl.so.1 jconfig.h libnl-3.a libnss_compat-2.8.so jerror.h libnl-3.la libnss_compat.so.2 jmorecfg.h libnl-3.so libnss_dns-2.8.so jpeglib.h libnl-3.so.200 libnss_dns.so.2 ld-2.8.so libnl-3.so.200.18.0 libnss_files-2.8.so ld-linux.so.3 libnl-cli-3.a libnss_files.so.2 libanl-2.8.so libnl-cli-3.la libnss_hesiod-2.8.so libanl.so.1 libnl-cli-3.so libnss_hesiod.so.2 libBrokenLocale-2.8.so libnl-cli-3.so.200 libnss_nis-2.8.so libBrokenLocale.so.1 libnl-cli-3.so.200.18.0 libnss_nisplus-2.8.so libc-2.8.so libnl-genl-3.a libnss_nisplus.so.2 libcidn-2.8.so libnl-genl-3.la libnss_nis.so.2 libcidn.so.1 libnl-genl-3.so libpcprofile.so libcrypt-2.8.so libnl-genl-3.so.200 libpthread-2.8.so libcrypto.a libnl-genl-3.so.200.18.0 libpthread.so.0 libcrypto.so libnl-idiag-3.a libresolv-2.8.so libcrypto.so.1.0.0 libnl-idiag-3.la libresolv.so.2 libcrypt.so.1 libnl-idiag-3.so librt-2.8.so libc.so.6 libnl-idiag-3.so.200 librt.so.1 libdl-2.8.so libnl-idiag-3.so.200.18.0 libSegFault.so libdl.so.2 libnl-nf-3.a libssl.a libfreetype.a libnl-nf-3.la libssl.so libfreetype.la libnl-nf-3.so libssl.so.1.0.0 libfreetype.so libnl-nf-3.so.200 libthread_db-1.0.so libfreetype.so.6 libnl-nf-3.so.200.18.0 libthread_db.so.1 libfreetype.so.6.9.0 libnl-route-3.a libutil-2.8.so libgcc_s.so libnl-route-3.la libutil.so.1 libgcc_s.so.1 libnl-route-3.so libz.a libm-2.8.so libnl-route-3.so.200 pkgconfig libmemusage.so libnl-route-3.so.200.18.0 turbojpeg.h libm.so.6 libnsl-2.8.so
然后,打开这个文件。
vi src/drivers/drivers.mk +31
发现下面这几句。
ifdef CONFIG_LIBNL32
DRV_LIBS += -lnl-3
DRV_LIBS += -lnl-genl-3
DRV_CFLAGS += -DCONFIG_LIBNL20 -I/usr/include/libnl3
那么我们只需要,在配置文件.config里,加 CONFIG_LIBNL32 = y 就可以了。