Ruby 扩展链接错误

发布于 2024-10-30 01:12:49 字数 694 浏览 7 评论 0原文

每当我尝试链接 我的 Ruby 扩展 时,我总是收到这个相当模糊的链接错误:

/usr/bin/ld: Mg.o: relocation R_X86_64_PC32 against undefined symbol `init_window_class_under' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value

我找不到任何东西关于这一点。我试验了一段时间,当我删除头文件时,它链接得很好,所以我在没有它们的情况下继续前进(是的,非常糟糕的主意)。

事实证明我现在需要它们。那么,这个错误到底是什么,如何消除它呢?

更新:清除所有内容后,我开始收到这些警告:

warning: ‘init_window_class_under’ used but never defined
warning: ‘init_display_mode_class_under’ used but never defined

当我第一次遇到问题时,这些警告也会出现。我不太确定它们的意思。

I keep getting this fairly obscure link error whenever I try to link my Ruby extension:

/usr/bin/ld: Mg.o: relocation R_X86_64_PC32 against undefined symbol `init_window_class_under' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value

I couldn't find anything on this. I experimented for a while and it linked fine when I removed the header files, so I moved on without them (Yes, very bad idea).

Turns out I need them, now. So, what is this error exactly, and how do I eliminate it?

Update: After clearing everything, I started getting these warnings:

warning: ‘init_window_class_under’ used but never defined
warning: ‘init_display_mode_class_under’ used but never defined

These also appeared when I first encountered the problem. I'm not exactly sure about what they mean.

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

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

发布评论

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

评论(2

_畞蕅 2024-11-06 01:12:49

更新后的错误告诉您,您正在某处引用 init_window_class_underinit_display_mode_class_under 但它们尚未定义。这些函数实际上是在 Window.c 中定义的,但它们在源文件和头文件中都声明为 static。从 Window.c 中的函数中删除 static 链接修饰符,并在 Window.h 中将它们声明为 extern。看来您在 Display.c 以及 x11 子目录中的所有内容中犯了同样的错误。

任何声明为 static 的内容都具有文件作用域,并且在文件本身之外不可见。

您原来的错误:

undefined symbol `init_window_class_under'

发生是因为 Window.c 中的所有函数(特别是 init_window_class_under)都是 staticstatic 函数不会产生任何可供链接器查找的符号。只有具有外部链接的实体才会在目标文件中产生符号。

Your updated error is telling you that you're referencing init_window_class_under and init_display_mode_class_under somewhere but they are not defined. Those functions are actually defined in Window.c but they're declared static in both the source file and header file. Remove the static linkage modifiers from the functions in Window.c and declare them as extern in Window.h. Looks like you're making the same mistake in Display.c and everything in the x11 subdirectory.

Anything declared as static has file scope and is not visible outside the file itself.

Your original error:

undefined symbol `init_window_class_under'

occurs because all the functions in Window.c (and init_window_class_under in particular) are static and static functions do not result in any symbols for the linker to find. Only entities with external linkage result in symbols in the object files.

假装不在乎 2024-11-06 01:12:49

正如错误消息所暗示的那样,目标文件必须使用 -fPIC 构建才能链接到 x86-64 上的共享库(这在其他平台上也是一个好主意)。

-fPIC 添加到您的 CFLAGS 并重建所有对象。

As the error message implies, object files must be built with -fPIC to be linked into shared libraries on x86-64 (it's a good idea on other platforms, too).

Add -fPIC to your CFLAGS and rebuild all objects.

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