【问题标题】:Compiling against gpsd on OpenWRT - linking fails在 OpenWRT 上针对 gpsd 进行编译 - 链接失败
【发布时间】:2020-02-15 03:43:07
【问题描述】:

我正在尝试编译一个使用gps.h 的工具,但每次尝试链接到libgps 时,我的编译似乎都失败了。我收到的错误信息是:

/opt/openwrt-sdk/staging_dir/toolchain-arm_cortex-a9+vfpv3_gcc-7.3.0_musl_eabi/bin/../lib/gcc/arm-openwrt-linux-muslgnueabi/7.3.0/../../../../arm-openwrt-linux-muslgnueabi/bin/ld: cannot find -lgps

这是我正在编译的命令:

arm-openwrt-linux-gcc -o ./bin/eagle src/main.c -I./src -I/opt/openwrt-sdk/staging_dir/target-arm_cortex-a9+vfpv3_musl_eabi/usr/include -static -L/opt/openwrt-sdk/staging_dir/target-arm_cortex-a9+vfpv3_musl_eabi/usr/lib  -lpthread -lgps

基本代码供参考:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <gps.h>

int main(void)
{
  int rc;
  struct gps_data_t gps_data;
  if ((rc = gps_open("localhost", "2947", &gps_data)) == -1)
  {
    printf("code: %d, reason: %s\n", rc, gps_errstr(rc));
    return 1;
  }
  gps_stream(&gps_data, WATCH_ENABLE | WATCH_JSON, NULL);

  return 0;
}

我的工具链中的一些目录列表 - 据我所知,libgps 已成功编译:

# ls -lah /opt/openwrt-sdk/staging_dir/target-arm_cortex-a9+vfpv3_musl_eabi/usr/include/ | grep gps

-rw-rw-r-- 1 root root  80K Sep  7  2017 gps.h

# ls -lah /opt/openwrt-sdk/staging_dir/target-arm_cortex-a9+vfpv3_musl_eabi/usr/lib/ | grep gps

lrwxrwxrwx 1 root root   16 Oct 17 18:46 libgps.so -> libgps.so.23.0.0
lrwxrwxrwx 1 root root   16 Oct 17 18:46 libgps.so.23 -> libgps.so.23.0.0
-rwxr-xr-x 1 root root 101K Oct 17 18:46 libgps.so.23.0.0

非常感谢您的帮助。

【问题讨论】:

  • 你可能没有为你的包上的库定义依赖。

标签: c linker router openwrt gpsd


【解决方案1】:

您的链接命令行包含“-static”,它阻止链接到 *.so 共享库(又名共享对象,因此是“so”),但仍然允许链接到 *.a 静态链接库(又名档案)。 见:https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

在您列出其内容以及链接命令行使用“-L”标志指向的目录中,有一个共享对象 libgps.so,但没有静态链接库 libgps.a。

这使得链接器无法满足链接时对 libgps 的依赖。满足它的唯一方法是使用 libgps.so,已使用“-static”禁用。

要修复,要么:

  1. 修改工具的编译配方,将链接命令行中的“-static”去掉,从而可以使用共享对象,或者
  2. 修改 gpsd 的编译配方,以构建静态链接库 libgps.a,添加或替代 libgps.so。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-09
    • 2011-12-06
    • 2020-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-14
    • 1970-01-01
    相关资源
    最近更新 更多