交叉编译时如何链接库

问题描述 投票:0回答:1

我正在交叉编译开放的VMWare工具。我预编译了glib,并设置了PKG_CONFIG_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'

我关注了这篇有用的文章(DESTDIR and PREFIX of make),但我认为我缺少一些东西。我没有为任何模块设置--prefix,因为我想在部署时使用默认的目录结构。

glib编译(下部模块):

./configure --host=${CROSS_COMPILE_HOST}
make
make install DESTDIR=/home/xport/

open-vmware-tools编译(上部模块):

export PKG_CONFIG_SYSROOT_DIR="/home/xport/"
export PKG_CONFIG_PATH="/home/xport/usr/local/lib/pkgconfig"
autoreconf -i
./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
make
make install DESTDIR=/home/xport # <-- I don't even get here

在设置PKG_CONFIG_PATH变量之前,第二个make由于缺少.h文件而失败...因此,我知道.pc链接有效。我想念什么?谢谢!

c linux ld pkg-config vmware-tools
1个回答
0
投票
./configure --host=${CROSS_COMPILE_HOST} ...

由于Autoconf错误,您需要同时设置--build--host。假设您正在为ARMv7l进行构建,例如:

./configure --host=$(config.guess) --build=armv7l-unknown-linux-gnueabihf

[以下内容对我来说似乎不错,假设/home/xport/usr/local/lib/pkgconfig有效,并且/home/xport/usr/local是拱的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

CFLAGSCXXFLAGS应该可能包含--sysroot。也许像这样:

./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" \
./configure --host=$(config.guess) --build=armv7l-unknown-linux-gnueabihf \
    --enable-lib64=no --without-kernel-modules ...

DESTDIR用于登台。看起来不错:

make install DESTDIR=/home/xport/

如果要从/home/xport/目录运行,则应考虑将以下内容添加到LDFLAGS

# 64-bit Fedora
-Wl,--enable-new-dtags -Wl,-R,'$$ORIGIN/../lib64'
# Most others
-Wl,--enable-new-dtags -Wl,-R,'$$ORIGIN/../lib'

所以也许像:

    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中的双美元符号归因于Makefile。双美元符号是一种逃避美元符号的方式,因此它可以正确地通过makefile。

另请参阅How to include correctly -Wl,-rpath,$ORIGIN linker argument in a 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手册中的2.2.8 Cross-Compilation

交叉编译是在一个平台上构建将在以下平台上运行的二进制文件:另一个平台。说到交叉编译,这一点很重要区分编译所在的构建平台执行,并在其上生成结果可执行文件的主机平台有望运行。以下配置选项用于指定每个人:

-build = build

构建软件包的系统。

-host = host

将运行内置程序和库的系统。

还有一点向下:

-host和--build选项通常是我们所需要的交叉编译。唯一的例外是如果正在构建的软件包是本身是交叉编译器:我们需要第三个选项来指定其目标建筑。

-target = target

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

© www.soinside.com 2019 - 2024. All rights reserved.