将某些库与 riscv 链接器链接时出现问题
Problems linking some libraries with riscv linker
我正在尝试使用创建的编译器 here (riscv64-linux) 编译一组文件。但是,我遇到了一些问题,我认为是我对图书馆的误解造成的。
我在 Makefile 中包含库 libgcc,在 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".
这让我想知道:
这真的意味着该库位于该路径中吗?
如何添加到该编译器的 SEARCH_DIR 的路径?
我认为它可能会发生,因为它需要一个静态库。为此,我尝试通过在 Makefile LINKER_INCLUDES = -L/home/laumecha/noelv-buildroot/output/host/lib/gcc/riscv64-buildroot-linux-musl/8.3.0/
中添加 link 静态 libgcc 库 (libgcc.a),在此路径中,我们可以找到 libgcc.a。为什么 linker 仍然找不到 -lgcc?
当我加上 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/
对于 linker 标志,我得到了多个未定义的引用:
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'
这是否意味着我已成功 link 编辑了图书馆,而我还缺少其他图书馆?
注意:我没有放入 Makefile 中的代码,因为我知道我的问题出在我的基本概念上,而 Makefile 是在某个官方网站上制作的。
问题是 link 用户正在寻找 libgcc.so 或 libgcc.a,但在您的文件夹中您有 libgcc_s.so,这是不一样的。
您可以在 linker 脚本中提供 SEARCH_DIR,或者您可以使用更容易的选项 -L
。
所有未定义的引用都是来自 libc 的函数。但是您的文件夹中没有 libc 。您将需要提供 libc 或提供这些功能。
一个建议。如果您不确切地知道自己在做什么,最好 link 使用默认情况下知道要使用的库及其位置的编译器。
我正在尝试使用创建的编译器 here (riscv64-linux) 编译一组文件。但是,我遇到了一些问题,我认为是我对图书馆的误解造成的。
我在 Makefile 中包含库 libgcc,在 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".
这让我想知道:
这真的意味着该库位于该路径中吗?
如何添加到该编译器的 SEARCH_DIR 的路径?
我认为它可能会发生,因为它需要一个静态库。为此,我尝试通过在 Makefile
LINKER_INCLUDES = -L/home/laumecha/noelv-buildroot/output/host/lib/gcc/riscv64-buildroot-linux-musl/8.3.0/
中添加 link 静态 libgcc 库 (libgcc.a),在此路径中,我们可以找到 libgcc.a。为什么 linker 仍然找不到 -lgcc?当我加上
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/
对于 linker 标志,我得到了多个未定义的引用:
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'
这是否意味着我已成功 link 编辑了图书馆,而我还缺少其他图书馆?
注意:我没有放入 Makefile 中的代码,因为我知道我的问题出在我的基本概念上,而 Makefile 是在某个官方网站上制作的。
问题是 link 用户正在寻找 libgcc.so 或 libgcc.a,但在您的文件夹中您有 libgcc_s.so,这是不一样的。
您可以在 linker 脚本中提供 SEARCH_DIR,或者您可以使用更容易的选项 -L
。
所有未定义的引用都是来自 libc 的函数。但是您的文件夹中没有 libc 。您将需要提供 libc 或提供这些功能。
一个建议。如果您不确切地知道自己在做什么,最好 link 使用默认情况下知道要使用的库及其位置的编译器。