【发布时间】:2017-11-01 08:47:16
【问题描述】:
我在 Xilinx sdk 工作,我正在开发共享库,我通过使用创建了一个共享库 (libhello.so)
aarch64-none-elf-gcc -shared -o libhello.so ../src/helloworld.o
创建库后,我将其动态加载到我的 c 文件中
void *handle;
void (*foo)(void);
handle = dlopen("/proj/ssw_xhd/boot/balakrish/workspace/hello_world/Debug/libhello.so", RTLD_GLOBAL);
foo = dlsym(handle,"foo");
if (foo){
library_function();
}
dlclose(handle);
但我收到如下错误
<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+0x1a0): undefined reference to `dlsym'
<artificial>:(.text.startup+0x1a0): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `dlsym'
<artificial>:(.text.startup+0x1a8): undefined reference to `library_function'
<artificial>:(.text.startup+0x1a8): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `library_function'
<artificial>:(.text.startup+0x1b0): undefined reference to `dlclose'
<artificial>:(.text.startup+0x1b0): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `dlclose'
collect2: error: ld returned 1 exit status
make: *** [fsbl.elf] Error 1
我还尝试在 C/C++ Build settings->ARM v8 gcc linker->libraries->libraries(dl)->library paths(/usr/lib/ or /usr/lib64/) 中添加 -ldl 并得到错误
Building target: fsbl.elf
Invoking: ARM v8 gcc linker
aarch64-none-elf-gcc -L"/proj/ssw_xhd/boot/balakrish/workspace/hello_world/Debug" -L/usr/lib64/ -L/usr/local/lib -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 -ldl -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
/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
14:08:01 Build Finished (took 5s.747ms)
【问题讨论】:
标签: c sdk linker shared-libraries dynamic-loading