我正在将Xilinx SDK与交叉编译器一起使用作为aarch64-none-elf-gcc
我正在程序中加载共享库,并且由于
Building target: fsbl.elf
Invoking: ARM v8 gcc linker
aarch64-none-elf-gcc -L"/proj/ssw_xhd/boot/balakrish/workspace/hello_world/Debug" -Lwrk/released/2017.3/GA/2017.3_1005_1/installs/lin64/SDK/2017.3/gnu/aarch64/lin/aarch64-none/bin/../lib/gcc/aarch64-none-elf/6.2.1/../../../../aarch64-none-elf/bin/ld -Wl,-T -Wl,../src/lscript.ld -L../../fsbl_bsp/psu_cortexa53_0/lib -o "fsbl.elf" ./src/psu_init.o ./src/xfsbl_authentication.o ./src/xfsbl_board.o ./src/xfsbl_bs.o ./src/xfsbl_csu_dma.o ./src/xfsbl_dfu_util.o ./src/xfsbl_exit.o ./src/xfsbl_handoff.o ./src/xfsbl_hooks.o ./src/xfsbl_image_header.o ./src/xfsbl_initialization.o ./src/xfsbl_main.o ./src/xfsbl_misc.o ./src/xfsbl_misc_drivers.o ./src/xfsbl_nand.o ./src/xfsbl_partition_load.o ./src/xfsbl_plpartition_valid.o ./src/xfsbl_qspi.o ./src/xfsbl_rsa_sha.o ./src/xfsbl_sd.o ./src/xfsbl_translation_table.o ./src/xfsbl_usb.o -lhello -Wl,--start-group,-lxil,-lgcc,-lc,--end-group -Wl,--start-group,-lxilffs,-lxil,-lgcc,-lc,--end-group -Wl,--start-group,-lxilsecure,-lxil,-lgcc,-lc,--end-group -Wl,--start-group,-lxilpm,-lxil,-lgcc,-lc,--end-group -n
/tmp/ccjtx6CQ.ltrans0.ltrans.o: In function `main':
<artificial>:(.text.startup+0x18c): undefined reference to `dlopen'
<artificial>:(.text.startup+0x18c): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `dlopen'
<artificial>:(.text.startup+0x19c): undefined reference to `dlsym'
<artificial>:(.text.startup+0x19c): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `dlsym'
<artificial>:(.text.startup+0x1a4): undefined reference to `library_function'
<artificial>:(.text.startup+0x1a4): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `library_function'
<artificial>:(.text.startup+0x1ac): undefined reference to `dlclose'
<artificial>:(.text.startup+0x1ac): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `dlclose'
collect2: error: ld returned 1 exit status
make: *** [fsbl.elf] Error 1
最后我的问题是如何在交叉编译中加载-ldl
如果我在C/C++ Build settings-.libraries-> library path中使用-ldl。我收到错误消息
/wrk/released/2017.3/GA/2017.3_1005_1/installs/lin64/SDK/2017.3/gnu/aarch64/lin/aarch64-none/bin/../lib/gcc/aarch64-none-elf/6.2.1/../../../../aarch64-none-elf/bin/ld: cannot find -ldl
collect2: error: ld returned 1 exit status
make: *** [fsbl.elf] Error 1
最佳答案
您的答案的不同部分似乎存在冲突。dlopen
,dlsym
和friends用于从文件系统上另一个文件加载代码。换句话说,这些功能与在运行时从目标平台文件系统和操作系统上可用的库中加载代码有关。
在交叉编译的情况下,工具链需要提供具有这些功能的实现的库(libdl.so
或libdl.a
)。工具链提供了具有相关操作系统调用的代码,以使用该代码打开文件,将其映射到内存并将其链接到正在运行的程序中。
冲突在哪里发挥作用。您提到的工具链似乎是裸机工具链。换句话说,这是一个无需操作系统即可直接在芯片上运行代码的工具链。如果没有操作系统,很明显,您不能使用它来在运行时加载更多代码。
考虑到这一点,显而易见的是,为什么工具链没有为您提供libdl.a
的适当实现。它不能在平台上通用实现。