首页 > 解决方案 > 如何仅使用命令行选项交叉编译 scons 附带的 gpsd

问题描述

我试图弄清楚如何在 buildroot 环境中将 GPSD 3.16 交叉编译为外部包。我已经能够告诉 scons 它应该使用哪个编译器并生成正确的编译文件。

    scons target=arm-buildroot-linux-gnueabihf-gcc
    file gpsd
    gpsd: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 4.9.0, not stripped

所以它通常可以工作,但是当 scons 尝试将 cgps 与 ncurses 链接时,构建会失败。当然 scons 会产生错误,因为它试图链接到 buildroot 主机 ncurses 库。

    arm-buildroot-linux-gnueabihf-gcc -o cgps -pthread -Wl,-rpath,/buildroot/host/usr/lib -Wl,-rpath,/buildroot/host/lib cgps.o -L. -L/buildroot/host/usr/lib -lgps_static -lm -lrt -lncurses /buildroot/host/usr/lib/libncurses.so: file not recognized: File format not recognized

首先,我尝试使用命令行选项 includeir 和 libdir,它们指向目标文件,但 scons 仍然只使用主机 ncurses 库。但似乎 scons 在编译其他 gpsd 组件时使用了正确的 includedir。

    arm-buildroot-linux-gnueabihf-gcc -o lcdgps.o -c -Wmissing-prototypes -Wextra -Wall -Wno-uninitialized -Wno-missing-field-initializers -Wcast-align -Wmissing-declarations -Wstrict-prototypes -Wpointer-arith -Wreturn-type -pthread -Wmissing-declarations -O2 -pthread "-I/target/usr/local/include -I/target/usr/local/include/ncurses"

我也尝试使用 pkgconfig 命令行选项,但得到了相同的结果。

到目前为止,我无法让 scons 使用目标 ncurses 库而不是主机库。在此项目中无法使用 GPSD 作为内部 buildroot 包,因此我正在寻找基于外部 GPSD 包的解决方案,而无需更改构造文件。

标签: cross-compilingsconsbuildrootgpsd

解决方案


通过使用与 LDFLAGS 相同的设置设置环境变量 LINKFLAGS,构建过程现在可以正常工作。

但是我不明白为什么通过设置includedir和libdir它不起作用。


推荐阅读