链接 C++ 时惰性符号绑定失败动态库

发布于 2024-09-11 08:55:06 字数 2816 浏览 6 评论 0原文

我正在用 C++ 编写一个 dylib,但是当我尝试将其链接到我的应用程序时,它在执行时给我一个错误:

dyld: lazy symbol binding failed: Symbol not found: __ZN8Vector2DC1Ev
  Referenced from: /Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug/Singularity Test App
  Expected in: /Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug/libSingularity.dylib

dyld: Symbol not found: __ZN8Vector2DC1Ev
  Referenced from: /Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug/Singularity Test App
  Expected in: /Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug/libSingularity.dylib

我确保符号没有被剥离,并

nm -g libSingularity.dylib  | grep "T" | grep __ZN8Vector

报告该符号存在于库中:

0000000000006df6 T __ZN8Vector2DC1Eff
0000000000006d98 T __ZN8Vector2DC1Ev
0000000000006dc2 T __ZN8Vector2DC2Eff
0000000000006d6e T __ZN8Vector2DC2Ev

I我是从 XCode 内部链接的,所以链接命令有点奇怪。 这是 dylib 的链接器命令:

Ld "/Users/noahz/Desktop/Singularity/Singularity Engine/build/Debug
    /libSingularity.dylib" normal x86_64
cd "/Users/noahz/Desktop/Singularity/Singularity Engine"
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/g++-4.2 -arch x86_64 -dynamiclib -isysroot /Develope
    /SDKs/MacOSX10.6.sdk "-L/Users/noahz/Desktop/Singularity/Singularity Engine/build
    /Debug" "-F/Users/noahz/Desktop/Singularity/Singularity Engine/build/Debug"
    -filelist "/Users/noahz/Desktop/Singularity/Singularity Engine/build/Singularity 
    Engine.build/Debug/Singularity Engine.build/Objects-normal/x86_64
    /libSingularity.LinkFileList" -install_name libSingularity.dylib -mmacosx-version-
    min=10.6 -framework sfml-system-d -framework sfml-window-d -framework SFML 
    -framework OpenGL -framework OpenAL -framework sfml-graphics-d -single_module 
    -compatibility_version 1 -current_version 1 -o "/Users/noahz/Desktop/Singularity
    /Singularity Engine/build/Debug/libSingularity.dylib"

这是测试应用程序的链接器命令:

cd "/Users/noahz/Desktop/Singularity/Singularity Test App"
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/g++-4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk 
    "-L/Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug" "-F/Users
    /noahz/Desktop/Singularity/Singularity Test App/build/Debug" -filelist "/Users/noahz
    /Desktop/Singularity/Singularity Test App/build/Singularity Test App.build/Debug
    /Singularity Test App.build/Objects-normal/x86_64/Singularity Test 
    App.LinkFileList" -mmacosx-version-min=10.6 "/Users/noahz/Desktop/Singularity
    /Singularity Engine/build/Debug/libSingularity.dylib" -o "/Users/noahz/Desktop
    /Singularity/Singularity Test App/build/Debug/Singularity Test App"

关于为什么会发生这种情况和/或如何修复它有什么想法吗?

I'm writing a dylib in C++, but when I try to link it into my application, it gives me an error on execution:

dyld: lazy symbol binding failed: Symbol not found: __ZN8Vector2DC1Ev
  Referenced from: /Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug/Singularity Test App
  Expected in: /Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug/libSingularity.dylib

dyld: Symbol not found: __ZN8Vector2DC1Ev
  Referenced from: /Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug/Singularity Test App
  Expected in: /Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug/libSingularity.dylib

I made sure the symbol wasn't stripped, and

nm -g libSingularity.dylib  | grep "T" | grep __ZN8Vector

reports that the symbol is present in the library:

0000000000006df6 T __ZN8Vector2DC1Eff
0000000000006d98 T __ZN8Vector2DC1Ev
0000000000006dc2 T __ZN8Vector2DC2Eff
0000000000006d6e T __ZN8Vector2DC2Ev

I'm linking from inside XCode, so the link commands are kind of weird.
Here's the linker command for the dylib:

Ld "/Users/noahz/Desktop/Singularity/Singularity Engine/build/Debug
    /libSingularity.dylib" normal x86_64
cd "/Users/noahz/Desktop/Singularity/Singularity Engine"
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/g++-4.2 -arch x86_64 -dynamiclib -isysroot /Develope
    /SDKs/MacOSX10.6.sdk "-L/Users/noahz/Desktop/Singularity/Singularity Engine/build
    /Debug" "-F/Users/noahz/Desktop/Singularity/Singularity Engine/build/Debug"
    -filelist "/Users/noahz/Desktop/Singularity/Singularity Engine/build/Singularity 
    Engine.build/Debug/Singularity Engine.build/Objects-normal/x86_64
    /libSingularity.LinkFileList" -install_name libSingularity.dylib -mmacosx-version-
    min=10.6 -framework sfml-system-d -framework sfml-window-d -framework SFML 
    -framework OpenGL -framework OpenAL -framework sfml-graphics-d -single_module 
    -compatibility_version 1 -current_version 1 -o "/Users/noahz/Desktop/Singularity
    /Singularity Engine/build/Debug/libSingularity.dylib"

and here's the linker command for the test app:

cd "/Users/noahz/Desktop/Singularity/Singularity Test App"
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/g++-4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk 
    "-L/Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug" "-F/Users
    /noahz/Desktop/Singularity/Singularity Test App/build/Debug" -filelist "/Users/noahz
    /Desktop/Singularity/Singularity Test App/build/Singularity Test App.build/Debug
    /Singularity Test App.build/Objects-normal/x86_64/Singularity Test 
    App.LinkFileList" -mmacosx-version-min=10.6 "/Users/noahz/Desktop/Singularity
    /Singularity Engine/build/Debug/libSingularity.dylib" -o "/Users/noahz/Desktop
    /Singularity/Singularity Test App/build/Debug/Singularity Test App"

Any ideas on why this is happening and/or how to fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沧笙踏歌 2024-09-18 08:55:06

如果您的应用程序的架构 x86/64 与您尝试加载的库不同,这可能可以解释您遇到的问题。

两者必须使用相同的体系结构进行编译。

If your application differs in architecture x86/64 from the library you are trying to load, that might explain the problem you're having.

Both must be compiled with the same architecture.

夜访吸血鬼 2024-09-18 08:55:06

我在链接阶段没有看到一行

-lSingularity

显然加载动态库的另一种方法是从内部显式加载它
代码。

gSystem->Load("libSingularity");

我只是解释一下我找到的一篇博客文章。

http://root.cern.ch /phpBB3//viewtopic.php?f=3&t=10380&start=0

I don't see a line in your link stage

-lSingularity

apparently another way to load a dynamic library is to explicity load it from within
the code.

gSystem->Load("libSingularity");

I'm just paraphrasing a blog article I found.

http://root.cern.ch/phpBB3//viewtopic.php?f=3&t=10380&start=0

夕色琉璃 2024-09-18 08:55:06

我通过静态链接库解决了这个问题。它不像动态链接那么优雅,但至少它不会反复崩溃。

I solved the problem by linking the library statically. It's not as elegant as dynamic linking was, but at least it doesn't crash repeatedly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文