【问题标题】:Problems linking some libraries with riscv linker使用 riscv 链接器链接某些库时出现问题
【发布时间】:2021-03-09 06:24:04
【问题描述】:

我正在尝试使用创建的编译器 here (riscv64-linux) 编译一组文件。但是,我遇到了一些问题,我认为这是我对库的误解造成的。

我将库 libgcc 包含在 Makefile 中,并在 LINKER_FLAGS 部分带有标志 -lgcc。但是,我得到以下输出:

riscv64-linux-ld: cannot find -lgcc

当我执行 $ riscv64-linux-ld --verbose | grep SEARCH_DIR | tr -s ' ;' \\012 要查看 riscv64-linux-ld 在哪里寻找库,我得到了多个路径。其中之一是 /home/luna/noelv-buildroot/output/host/riscv64-buildroot-linux-musl/lib".

但是,当我看到该路径的内容时,我可以找到 libgcc 库:

$ ls /home/luna/noelv-buildroot/output/host/riscv64-buildroot-linux-musl/lib
ldscripts    libatomic.la  libatomic.so.1      libgcc_s.so
libatomic.a  libatomic.so  libatomic.so.1.2.0  libgcc_s.so.1". 

这让我想知道:

  1. 这是否真的意味着该库位于该路径中?

  2. 如何向该编译器的 SEARCH_DIR 添加路径?

  3. 我认为它可能会发生,因为它需要一个静态库。为此,我尝试通过添加 Makefile LINKER_INCLUDES = -L/home/laumecha/noelv-buildroot/output/host/lib/gcc/riscv64-buildroot-linux-musl/8.3.0/ 来链接静态 libgcc 库 (libgcc.a),在此路径中,我们可以找到 libgcc.a。为什么链接器仍然找不到-lgcc?

  4. 当我添加 LINKER_FLAGS += -lm -static -lgcc -nostartfiles -L/home/luna/noelv-buildroot/output/build/host-gcc-final-8.3.0/build/riscv64-buildroot-linux-musl/libgcc/ 到链接器标志,我得到了多个未定义的引用:

riscv64-linux-ld: /home/luna/multibench_automotive_2.0.2653/builds/riscv64/riscv-gcc64/obj/mith.a(th_al.o): in function `al_printf':
/home/luna/multibench_automotive_2.0.2653/mith/al/src/th_al.c:505: undefined reference to `vsscanf'
riscv64-linux-ld: /home/luna/multibench_automotive_2.0.2653/builds/riscv64/riscv-gcc64/obj/mith.a(th_al.o): in function al_sprintf':
/home/luna/multibench_automotive_2.0.2653/mith/al/src/th_al.c:523: undefined reference to `vfscanf'
riscv64-linux-ld: /home/luna/multibench_automotive_2.0.2653/builds/riscv64/riscv-gcc64/obj/mith.a(th_al.o): in function al_fcreate':
/home/luna/multibench_automotive_2.0.2653/mith/al/src/th_al.c:664: undefined reference to `strchr'
riscv64-linux-ld: /home/luna/multibench_automotive_2.0.2653/builds/riscv64/riscv-gcc64/obj/mith.a(th_al.o): in function `al_fsize':
/home/luna/multibench_automotive_2.0.2653/mith/al/src/th_al.c:693: undefined reference to `stat'
riscv64-linux-ld: /home/luna/multibench_automotive_2.0.2653/mith/al/src/th_al.c:714: undefined reference to `getenv'

这是否意味着我已成功链接库而我缺少其他库?

注意:我没有从 Makefile 中添加代码,因为我知道我的问题来自我的基本概念,并且 Makefile 是在某个官方网站上制作的。

【问题讨论】:

    标签: c++ linux makefile compiler-construction multiple-makefiles


    【解决方案1】:

    问题是链接器正在寻找 libgcc.so 或 libgcc.a 但在你的文件夹中你有 libgcc_s.so 这不一样。

    您可以在链接描述文件中提供 SEARCH_DIR,也可以使用更简单的选项-L。

    所有未定义的引用都是来自 libc 的函数。但是,您的文件夹中没有 libc。您将需要提供一个 libc 或提供这些功能。

    建议。如果您不确切知道自己在做什么,最好与默认情况下知道要使用的库及其位置的编译器链接。

    【讨论】:

    • 如果我查找编译器使用的库并将该库的路径传递给链接器,是否正确?由于 Makefile 的结构,我需要使用链接器。非常感谢您的回复。
    • 是的,通常你可以使用编译器默认使用的东西。您可以使用详细模式查看此信息。
    猜你喜欢
    • 2017-06-21
    • 1970-01-01
    • 2018-12-11
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多