交叉编译中遇到的问题

编译环境:

        ubuntu版本:ubuntu 14.04

        交叉编译工具链:OpenWrt-Toolchain-ramips-mt7628_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-i686

编译库:libosip2-3.5.0、libeXosip2-3.5.0

报错内容:

1、libosip2-3.5.0

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

2、libeXosip2-3.5.0

libtool: link: mipsel-openwrt-linux-gcc -g -DOSIP_MT -DENABLE_DEBUG -g -DENABLE_TRACE -g -o .libs/sip_reg sip_reg.o ../src/.libs/libeXosip2.so -L/usr/local/lib /usr/local/lib/libosipparser2.so /usr/local/lib/libosip2.so -lresolv
/usr/local/lib/libosip2.so: undefined reference to `pthread_create'
/usr/local/lib/libosip2.so: undefined reference to `sem_destroy'
/usr/local/lib/libosip2.so: undefined reference to `sem_wait'
/usr/local/lib/libosip2.so: undefined reference to `sem_post'
/usr/local/lib/libosip2.so: undefined reference to `sem_init'
/usr/local/lib/libosip2.so: undefined reference to `sem_trywait'
/usr/local/lib/libosip2.so: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status

解决方法:在执行./configure文件后加入参数 LDFLAGS='-ldl'

执行脚本:

1、libosip2-3.5.0

./configure --host=mipsel-openwrt-linux LDFLAGS='-ldl'
make clean
make
make install

2、libeXosip2-3.5.0

./configure --host=mipsel-openwrt-linux PKG_CONFIG_PATH=/usr/local/lib/pkgconfig LDFLAGS='-ldl'
make clean
make
make install

---------------------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------------------------------------

解决过程:

首先,我执行./configure -h查看帮助信息,发现

--enable-pthread enable support for POSIX threads. (default=autodetect)

所以在配置脚本中加入这个选项

./configure --host=mipsel-openwrt-linux --enable-pthread
make clean
make
make install

libosip2-3.5.0库可以成功配置、编译、安装,但是但是但是,这是错的

因为接下来就是要交叉编译 libeXosip2-3.5.0 这个库,而上面的库是这个库的依赖库,编译过程中会出现上面报错内容中libeXosip2-3.5.0 的错。

所以直接加 --enable-pthread 并不能解决问题,问题还是在于没有正确编译 libosip2-3.5.0 库,然后我对比没有使用工具链和使用工具链间的差异,发现交叉编译配置后生成的config.h文件中没有定义HAVE_PTHREAD宏,于是手动增加

#define HAVE_PTHREAD 1

这一语句,再次编译安装发现仍然不能解决问题,再接着就是分析两种配置的配置信息,没有使用工具链的配置信息如下

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... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... no

对比后可以得到前面是一致的,只有后面几行有差异,所以这次我把两次编译的config.log文件复制出来,在打印那几句不同调试信息的位置进行查找,最终发现了几行关键的调试信息

/opt/OpenWrt-Toolchain-ramips-mt7628_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-i686/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: warning: libdl.so.0, needed by /opt/OpenWrt-Toolchain-ramips-mt7628_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-i686/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/lib/libpthread.so.0, not found (try using -rpath or -rpath-link)
/opt/OpenWrt-Toolchain-ramips-mt7628_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-i686/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/lib/libpthread.so.0: undefined reference to `dlclose'
/opt/OpenWrt-Toolchain-ramips-mt7628_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-i686/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/lib/libpthread.so.0: undefined reference to `dlopen'
/opt/OpenWrt-Toolchain-ramips-mt7628_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-i686/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/lib/libpthread.so.0: undefined reference to `dlsym'

然后百度一搜,结果是缺少了LDFLAGS='-ldl' 选项,最后在两个库的配置编译脚本中都加上这个选项后,编译安装完美通过。

猜你喜欢

转载自blog.csdn.net/wg_rui/article/details/81739967