交叉编译中pkg-config和libtool设置

本文介绍了如何在交叉编译环境中正确配置pkg-config和Libtool,通过设置环境变量PKG_CONFIG_SYSROOT_DIR解决路径定位问题,并手动修改la文件中的依赖库路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.pkg-config

        pkg-config工具方便了编译的头文件、库文件的路径设置,它利用pc文件保存头文件、库文件和库依赖的相关信息。

        在交叉编译环境中,目标板的pc文件中保存的路径信息可能只是相对于目标板的根目录(nfs挂载目录)的路径,这样在主机端交叉编译时,pkg-config得到的路径无法正确定位到目标板上的交叉编译的库文件和头文件,编译无法正确进行。利用pkg-config环境变量PKG_CONFIG_SYSROOT_DIR可以较好解决这个问题,设置PKG_CONFIG_SYSROOT_DIR为目标板的根目录,pkg-config则会在pc文件中得到的路径加上前缀$PKG_CONFIG_SYSROOT_DIR,处理后的路径可以正确定位到库文件和头文件的位置。


2.Libtool

        Libtool工具可以在不同的平台中方便建立动态链接库,它隐藏了一些底层细节。libtool利用la文件记录库的位置和依赖关系,和上面的问题类似,在交叉编译环境中,它存放的是相对于目标板的根目录的路径,交叉编译会出现问题,貌似对于libtool的这种问题没有比较简单的解决方案,但修改la文件中的目录位置可以解决此种问题,主要修改la文件中的两处位置

  1. dependency_libs:保存的是库的依赖关系,修改为主机端的绝对路径
  2. libdir:保存的是库文件的位置,修改为主机端的绝对路径
用中文分析错误原因,给出解决方法cd zeromq-4.3.5/ [root@localhost:2 zeromq-4.3.5]# ./autogen.sh autoreconf: Entering directory `.' autoreconf: configure.ac: not using Gettext autoreconf: running: aclocal -I config --force -I config autoreconf: configure.ac: tracing autoreconf: running: libtoolize --copy --force libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'config'. libtoolize: copying file 'config/ltmain.sh' libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'config'. libtoolize: copying file 'config/libtool.m4' libtoolize: copying file 'config/ltoptions.m4' libtoolize: copying file 'config/ltsugar.m4' libtoolize: copying file 'config/ltversion.m4' libtoolize: copying file 'config/lt~obsolete.m4' autoreconf: running: /usr/bin/autoconf --include=config --force configure.ac:28: error: possibly undefined macro: AC_SUBST If this token and others are legitimate, please use m4_pattern_allow. See the Autoconf documentation. configure.ac:74: error: missing some pkg-config macros (pkg-config package) configure.ac:132: error: possibly undefined macro: AC_MSG_RESULT configure.ac:145: error: possibly undefined macro: AC_DEFINE configure.ac:253: error: possibly undefined macro: AC_CHECK_LIB configure.ac:356: error: possibly undefined macro: AC_CHECK_HEADERS configure.ac:358: error: possibly undefined macro: AC_MSG_ERROR configure.ac:545: error: missing some pkg-config macros (pkg-config package) configure.ac:550: error: possibly undefined macro: AC_SEARCH_LIBS configure.ac:593: error: possibly undefined macro: AC_MSG_NOTICE configure.ac:888: error: possibly undefined macro: AC_MSG_WARN autoreconf: /usr/bin/autoconf failed with exit status: 1 autogen.sh: error: autoreconf exited with status 1
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值