0

我正在尝试使用此处创建的编译器(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 来链接静态 libgcc 库 (libgcc.a) LINKER_INCLUDES = -L/home/laumecha/noelv-buildroot/output/host/lib/gcc/riscv64-buildroot-linux-musl/8.3.0/,在此路径中,我们可以找到 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 是在一些官方网站上制作的。

4

1 回答 1

1

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

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

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

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

于 2020-11-26T21:47:42.477 回答