交叉编译时如何 link 库

How to link libraries when cross compiling

我正在交叉编译开放的 VMWare 工具。我预编译了 glib 并将 PKG_CONFIG_PATH 变量设置为 link 它们。 我在 link 阶段遇到以下错误。

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'

我遵循了这个有用的 post (DESTDIR and PREFIX of make),但我想我遗漏了一些东西。 我没有为任何模块设置 --prefix,因为我想在部署时使用默认的 direcotry 结构。

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 变量之前,由于缺少 .h 文件,第二次 make 失败了...所以我知道 .pc linkage 有效。 我错过了什么? 谢谢!

./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 是 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

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。

另见


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

To cross-compile is to build on one platform a binary that will run on another platform. When speaking of cross-compilation, it is important to distinguish between the build platform on which the compilation is performed, and the host platform on which the resulting executable is expected to run. The following configure options are used to specify each of them:

--build=build

     The system on which the package is built.

--host=host

     The system where built programs and libraries will run.

再往下一点:

The --host and --build options are usually all we need for cross-compiling. The only exception is if the package being built is itself a cross-compiler: we need a third option to specify its target architecture.

--target=target

     When building compiler tools: the system for which the tools will create output.


关于评论"I don't even get here":

make
make install DESTDIR=/home/xport # <-- I don't even get here

您需要显示您在 运行 make.

时遇到的编译错误