未定义的符号引用 'dlsym@@GLIBC_2.2.5'

undefined reference to symbol 'dlsym@@GLIBC_2.2.5'

我在 qemu-5.1.0 中添加了一段代码,这段代码应该使用 .so 文件。
我使用配置 --extra-cflags/--extra-cxxflags/--extra-ldflags 选项将 -ldl 添加到 QEMU_CFLAGS、QEMU_CXXFLAGS、QEMU_LDFLAGS 并且可以看到它们确实已设置。
但是当我真正做“make”时,它给了我这个错误,我不知道哪里出了问题。

LINK    aarch64-softmmu/qemu-system-aarch64
/usr/bin/ld: ../hw/misc/axpu_if.o: undefined reference to symbol 'dlsym@@GLIBC_2.2.5'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libdl.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:219: qemu-system-aarch64] Error 1
make: *** [Makefile:527: aarch64-softmmu/all] Error 2

这是“ldd --version”命令的输出。我系统的 glibc 版本似乎是 2.31 (ubuntu 20.04),但我不知道为什么它要从 glibc_2.2.5.

中寻找符号 dlsym
ckim@ckim-ubuntu:~/xxx/qemu-5.1.0/build$ ldd --version
ldd (Ubuntu GLIBC 2.31-0ubuntu9.2) 2.31
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

谁能帮帮我?

我发现“-ldl”link 选项被忽略了,因为它在 make 期间在最终的 c++ link 命令中放置得太早了。所以如果你想使用外部.so文件并且需要使用libdl.so,你应该像这样配置qemu。 (在qemu-5.1.0/build目录下)

../configure --target-list=aarch64-softmmu --enable-debug --enable-gtk --extra-ldflags="-Wl,--no-as-needed,-ldl"

添加了 -Wl,--no-as-needed,-ldl 部分。 (其他的是为了我的需要)。 -as-needed 是默认值,它在 elf 文件中列出了所需的库。我只用 -ldl 测试了它,但它没有用,因此是最后的命令。