C 交叉编译时如何链接库

C 交叉编译时如何链接库,c,linux,ld,pkg-config,vmware-tools,C,Linux,Ld,Pkg Config,Vmware Tools,我正在交叉编译开放式VMWare工具。我预先编译了glib,并设置了PKG\u CONFIG\u PATH变量来链接它们。 我在链接阶段遇到以下错误 libtool: link: warning: library `/u/git/extlib_vmtools/usr/local/lib/libgthread-2.0.la' was moved. /bin/grep: /usr/local/lib/libglib-2.0.la: No such file or directory /bin/sed

我正在交叉编译开放式VMWare工具。我预先编译了glib,并设置了
PKG\u CONFIG\u PATH
变量来链接它们。 我在链接阶段遇到以下错误

libtool: link: warning: library `/u/git/extlib_vmtools/usr/local/lib/libgthread-2.0.la' was moved.
/bin/grep: /usr/local/lib/libglib-2.0.la: No such file or directory
/bin/sed: can't read /usr/local/lib/libglib-2.0.la: No such file or directory
libtool: link: `/usr/local/lib/libglib-2.0.la' is not a valid libtool archive
make[2]: *** [libhgfs.la] Error 1
make[2]: Leaving directory `/u/git/extlib_vmtools/src/open-vm-tools-11.0.0-14549434/libhgfs'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/u/git/extlib_vmtools/src/open-vm-tools-11.0.0-14549434'
我关注了这篇有用的帖子(),但我想我遗漏了一些东西。 我没有为任何模块设置
--prefix
,因为我希望在部署时使用默认的direcotry结构

glib编译(较低模块):

打开vmware工具编译(上模块):

export-PKG\u-CONFIG\u-SYSROOT\u-DIR=“/home/xport/”
导出PKG_CONFIG_PATH=“/home/xport/usr/local/lib/pkgconfig”
自动经济-i
./configure--host=${CROSS_COMPILE_host}--enable-lib64=no--不带内核模块--不带pam--禁用vgauth--不带-x--不带-gtk3--不带-gtk2--不带-gtkm3--不带gtkmm--enable resolutionkms=no--enable deploypkg=no
制作
使安装DESTDIR=/home/xport#
由于Autoconf错误,您需要同时设置
--build
--host
。假设您正在为ARMv7l构建,类似于:

./configure --host=$(config.guess) --build=armv7l-unknown-linux-gnueabihf
./configure --host=$(config.guess) --build=armv7l-unknown-linux-gnueabihf \
    --sysroot="/home/xport/usr/local" --enable-lib64=no --without-kernel-modules ...
    CFLAGS="--sysroot=/home/xport/usr/local" \
    CXXFLAGS="--sysroot=/home/xport/usr/local" \
    LDFLAGS="-Wl,--enable-new-dtags -Wl,-R,'$$ORIGIN/../lib'" \
./configure --host=$(config.guess) --build=armv7l-unknown-linux-gnueabihf \
    --enable-lib64=no --without-kernel-modules ...

假设
/home/xport/usr/local/lib/pkgconfig
有效,并且
/home/xport/usr/local
是arch的
include/
lib/
文件的位置,以下内容看起来没问题

export PKG_CONFIG_PATH="/home/xport/usr/local/lib/pkgconfig"

我不确定接下来会发生什么。它还缺少一个
--build
。我习惯于在交叉编译时看到一个
--sysroot

./configure --host=${CROSS_COMPILE_HOST} \
    --enable-lib64=no --without-kernel-modules --without-pam --disable-vgauth \
    --without-x --without-gtk3 --without-gtk2 --without-gtkmm3 --without-gtkmm \
    --enable-resolutionkms=no --enable-deploypkg=no
CFLAGS
cxflags
可能应该包括
--sysroot
。可能是这样的:

./configure --host=$(config.guess) --build=armv7l-unknown-linux-gnueabihf
./configure --host=$(config.guess) --build=armv7l-unknown-linux-gnueabihf \
    --sysroot="/home/xport/usr/local" --enable-lib64=no --without-kernel-modules ...
    CFLAGS="--sysroot=/home/xport/usr/local" \
    CXXFLAGS="--sysroot=/home/xport/usr/local" \
    LDFLAGS="-Wl,--enable-new-dtags -Wl,-R,'$$ORIGIN/../lib'" \
./configure --host=$(config.guess) --build=armv7l-unknown-linux-gnueabihf \
    --enable-lib64=no --without-kernel-modules ...
或:


DESTDIR
用于暂存。这看起来不错:

make install DESTDIR=/home/xport/
如果您打算从<代码> /home /xPruts/<代码>目录中运行,那么您应该考虑添加以下代码到LDFLAGs >:

# 64-bit Fedora
-Wl,--enable-new-dtags -Wl,-R,'$$ORIGIN/../lib64'
# Most others
-Wl,--enable-new-dtags -Wl,-R,'$$ORIGIN/../lib'
所以可能是这样的:

./configure --host=$(config.guess) --build=armv7l-unknown-linux-gnueabihf
./configure --host=$(config.guess) --build=armv7l-unknown-linux-gnueabihf \
    --sysroot="/home/xport/usr/local" --enable-lib64=no --without-kernel-modules ...
    CFLAGS="--sysroot=/home/xport/usr/local" \
    CXXFLAGS="--sysroot=/home/xport/usr/local" \
    LDFLAGS="-Wl,--enable-new-dtags -Wl,-R,'$$ORIGIN/../lib'" \
./configure --host=$(config.guess) --build=armv7l-unknown-linux-gnueabihf \
    --enable-lib64=no --without-kernel-modules ...
$ORIGIN
基于运行路径的运行路径是使用
DESTDIR
进行分阶段安装的原因

双美元登录
$$ORIGIN
是由Makefiles造成的。双美元符号是避开美元符号的方法,因此它可以正确地通过makefile

也看到


config.guess
为您提供了Autoconf三元组:

$/usr/share/libtool/build aux/config.guess
x86_64-pc-linux-gnu
如果路径上没有
config.guess
,请在
/usr/share
中检查它:

$find/usr/share-name config.guess
/usr/share/misc/config.guess
/usr/share/libtool/config/config.guess
/usr/share/automake-1.14/config.guess

另请参见Autoconf手册中的:

交叉编译就是在一个平台上构建一个将在其上运行的二进制文件 另一个平台。说到交叉编译,它很重要 区分编译所基于的构建平台 以及生成的可执行文件所在的主机平台 预计将运行。以下配置选项用于指定 其中每一项:

--建造

构建包的系统

--主机=主机

运行生成程序和库的系统

再往下一点:

我们通常只需要--host和--build选项 交叉编译。唯一的例外是正在生成的包是 它本身就是一个交叉编译器:我们需要第三个选项来指定它的目标 建筑

--目标=目标

构建编译器工具时:系统 工具将为其创建输出


关于“我甚至没有到这里”的评论:

make

使install DESTDIR=/home/xport#当您运行
configure
时,您需要指定要为其生成的目标,默认情况下,主机将连接到本地主机系统。@SomeProgrammerDude-close。使用
--build
,而不是
--target
<代码>--target
用于为arch构建编译器。非常混乱…好的测试。。。config.guess=x86\u 64-unknown-linux-gnu和CROSS\u COMPILE\u HOST=i686 linux。这样可以吗?你的评论仍然适用吗?因为glib(依赖项之一)未通过配置预检查。谢谢另外,/home/xport是我要在其中导出编译输出的stating目录。我将tgz这个目录,并在我的目标机器上解压缩它。因此,我认为不需要sysroot。@user2491552-根据
交叉编译\u主机
注释,如果要在32位i686上运行,您可能应该使用
交叉编译\u主机=i686未知linux gnu
--主机=i686未知linux gnu
。@user2491552-根据我的交叉编译经验,您想设置一个
--sysroot
。这是一个构建时选项,告诉工具链在哪里可以找到工具、标题和库<代码>--sysroot
不影响运行时。对于运行时,您希望编译并链接
-Wl,--enable new dtags-Wl,-R,'$$ORIGIN/./lib'
。这允许您在文件系统上移动程序。@user2491552-此时,我认为您应该重新启动。将适当的三元组用于
--build
--host
交叉编译\u host
。设置
CFLAGS
cxflags
LDFLAGS
。重新建造一切。当你遇到新问题时,问一个新问题。