【发布时间】:2013-09-13 23:44:45
【问题描述】:
我正在使用 Code sourcery g++ lite toolchain 2013。
有一个我集成到 buildroot 中的项目(这似乎很好,一切都按预期调用)。
waf 是首选的构建系统
define EEBUSRESTIFIED_CONFIGURE_CMDS
(cd "$(@D)"; \
$(TARGET_CONFIGURE_OPTS) \
CFLAGS="$(CFLAGS_FOR_BUILD)" \
LDFLAGS="--sysroot=$(STAGING_DIR)" \
LD_LIBRARY_PATH="$(STAGING_DIR)" \
PKG_CONFIG_PATH="$(STAGING_DIR)/usr/lib/pkgconfig" \
PKG_CONFIG_SYSROOT_DIR="$(STAGING_DIR)" \
./waf --dest=$(TARGET_DIR) configure)
endef
表演
Setting top to : /home/bernhard/buildroot-2013.08/output/build/foo-6508f5b36172ba8965372ef96fb350b413ec5d15
Setting out to : /home/bernhard/buildroot-2013.08/output/build/foo-6508f5b36172ba8965372ef96fb350b413ec5d15/build
Checking for program gcc,cc : /home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-gcc
Checking for program ar : /home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-ar
Checking for program glib-genmarshal : /home/bernhard/buildroot-2013.08/output/host/usr/bin/glib-genmarshal
Checking for program perl : /usr/bin/perl
Checking for 'glib-mkenums' : /home/bernhard/buildroot-2013.08/output/host/usr/bin/glib-mkenums
Checking for program glib-compile-schemas : /home/bernhard/buildroot-2013.08/output/host/usr/bin/glib-compile-schemas
Checking for program pkg-config : /home/bernhard/buildroot-2013.08/output/host/usr/bin/pkg-config
Checking for pkg-config version >= '0.26' : yes
Checking for 'glib-2.0' : yes
Checking for 'glib-2.0' version : yes
Checking for 'gobject-2.0' : yes
Checking for 'libsoup-2.4' : yes
Checking for 'libsoup-2.4' version : yes
Checking for 'libxml-2.0' : yes
Checking for 'uuid' : yes
Checking for endianness : little
Checking for inline : inline
看起来不错。
在编译阶段
define EEBUSRESTIFIED_BUILD_CMDS
(cd "$(@D)"; \
$(TARGET_CONFIGURE_OPTS) \
LDFLAGS="--sysroot=$(STAGING_DIR)" \
LD_LIBRARY_PATH="$(STAGING_DIR)" \
PKG_CONFIG_PATH="$(STAGING_DIR)/usr/lib/pkgconfig" \
PKG_CONFIG_SYSROOT_DIR="$(STAGING_DIR)" \
./waf --dest=$(TARGET_DIR) build)
endef
它死了
/home/bernhard/buildroot-2013.08/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-none-linux-gnueabi/4.6.1/../../../../arm-none-linux-gnueabi/bin/ld: warning: library search path "/usr/lib" is unsafe for cross-compilation
/home/bernhard/buildroot-2013.08/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-none-linux-gnueabi/4.6.1/../../../../arm-none-linux-gnueabi/bin/ld: warning: library search path "/usr/lib" is unsafe for cross-compilation
/usr/lib/libgobject-2.0.so: file not recognized: File format not recognized
collect2: ld returned 1 exit status
我明白这个问题 - waf/ld 试图链接我的主机库,这注定会失败。
如何修复 ld 以获取正确的库路径?这个问题的根源是什么?
这里是构建命令的扩展输出(用 linbreaks 替换空格):
echo
"PATH="/home/bernhard/buildroot-2013.08/output/host/bin:/home/bernhard/buildroot-2013.08/output/host/usr/bin:/home/bernhard/buildroot-2013.08/output/host/usr/sbin/:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl"
AR="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-ar"
AS="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-as"
LD="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-ld"
NM="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-nm"
CC="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-gcc"
GCC="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-gcc"
CPP="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-cpp"
CXX="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-g++"
FC="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-gfortran"
RANLIB="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-ranlib"
READELF="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-readelf"
STRIP="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-strip"
OBJCOPY="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-objcopy"
OBJDUMP="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-objdump"
AR_FOR_BUILD="/usr/bin/ar"
AS_FOR_BUILD="/usr/bin/as"
CC_FOR_BUILD="/usr/bin/gcc"
GCC_FOR_BUILD="/usr/bin/gcc"
CXX_FOR_BUILD="/usr/bin/g++"
FC_FOR_BUILD="/usr/bin/ld"
LD_FOR_BUILD="/usr/bin/ld"
CPPFLAGS_FOR_BUILD="-I/home/bernhard/buildroot-2013.08/output/host/usr/include"
CFLAGS_FOR_BUILD="-O2
-I/home/bernhard/buildroot-2013.08/output/host/usr/include"
CXXFLAGS_FOR_BUILD="-O2
-I/home/bernhard/buildroot-2013.08/output/host/usr/include"
LDFLAGS_FOR_BUILD="-L/home/bernhard/buildroot-2013.08/output/host/lib
-L/home/bernhard/buildroot-2013.08/output/host/usr/lib
-Wl,-rpath,/home/bernhard/buildroot-2013.08/output/host/usr/lib"
FCFLAGS_FOR_BUILD=""
DEFAULT_ASSEMBLER="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-as"
DEFAULT_LINKER="/home/bernhard/buildroot-2013.08/output/host/usr/bin/arm-none-linux-gnueabi-ld"
CPPFLAGS="-D_LARGEFILE_SOURCE
-D_LARGEFILE64_SOURCE
-D_FILE_OFFSET_BITS=64"
CFLAGS="-D_LARGEFILE_SOURCE
-D_LARGEFILE64_SOURCE
-D_FILE_OFFSET_BITS=64
-pipe
-O2
"
CXXFLAGS="-D_LARGEFILE_SOURCE
-D_LARGEFILE64_SOURCE
-D_FILE_OFFSET_BITS=64
-pipe
-O2
"
LDFLAGS=""
FCFLAGS=""
PKG_CONFIG="/home/bernhard/buildroot-2013.08/output/host/usr/bin/pkg-config"
PERLLIB="/home/bernhard/buildroot-2013.08/output/host/usr/lib/perl"
STAGING_DIR="/home/bernhard/buildroot-2013.08/output/host/usr/arm-buildroot-linux-gnueabi/sysroot""
I tried a couple of combinations for `PKG_CONFIG_*` , with/without `--sysroot` but no success so far.
已阅读linux cross compiling and dynamic libraries / linking
供参考,整个foo.mk
FOO_VERSION = abcd1234
FOO_SITE = ssh://git@some.where/FOO
FOO_SITE_METHOD = git
FOO_LICENSE = unknown
FOO_INSTALL_TARGET = YES
FOO_DEPENDENCIES = util-linux libglib2 libsoup libxml2 host-pkgconf
define FOO_CONFIGURE_CMDS
echo "$(TARGET_CONFIGURE_OPTS)"
(cd "$(@D)"; \
$(TARGET_CONFIGURE_OPTS) \
LDFLAGS="--sysroot=$(STAGING_DIR)" \
LD_LIBRARY_PATH="$(STAGING_DIR)" \
PKG_CONFIG_PATH="$(STAGING_DIR)/usr/lib/pkgconfig" \
PKG_CONFIG_SYSROOT_DIR="$(STAGING_DIR)" \
./waf --dest=$(TARGET_DIR) configure)
endef
define FOO_BUILD_CMDS
(cd "$(@D)"; \
LDFLAGS="--sysroot=$(STAGING_DIR)" \
LD_LIBRARY_PATH="$(STAGING_DIR)" \
PKG_CONFIG_PATH="$(STAGING_DIR)/usr/lib/pkgconfig" \
PKG_CONFIG_SYSROOT_DIR="$(STAGING_DIR)" \
./waf --dest=$(TARGET_DIR) debug)
endef
define FOO_INSTALL_TARGET_CMDS
(cd "$(@D)"; \
./waf --dest=$(TARGET_DIR) install)
endef
define FOO_CLEAN_CMDS
(cd "$(@D)"; \
./waf --dest=$(TARGET_DIR) distclean)
endef
$(eval $(generic-package))
【问题讨论】:
-
尝试用
PKG_CONFIG_LIBDIR替换PKG_CONFIG_PATH。 -
在配置和构建中都替换了它 - 没有变化
-
还测试了删除
--sysroot和/或PKG_CONFIG_SYSROOT_DIR的前突变 - 没有成功 -
没有 waf 方面的专家,但“狡猾的”
*_FOR_BUILD变量应该是由于FOO_BUILD_CMDS中缺少echo "$(TARGET_CONFIGURE_OPTS)"。但是,如果这将是基于 autotools 的配置和安装,我不会在构建状态下覆盖太多,因此请尝试在FOO_BUILD_CMDS中仅使用(cd "$(@D)"; ./waf --dest=$(TARGET_DIR) debug)。此外,将PKG_CONFIG_PATH="$(STAGING_DIR)/usr/lib/pkgconfig"替换为PKG_CONFIG_PATH="$(STAGING_DIR)/usr/lib/pkgconfig:$(STAGING_DIR)/lib/pkgconfig:$(STAGING_DIR)/usr/local/lib/pkgconfig"。 -
但它最终得到一个
x86_64二进制而不是 ARM 二进制
标签: c cross-compiling waf buildroot library-path