0

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.

4

2 回答 2

1

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

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

于 2011-04-04T00:04:33.257 回答
1

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

任何声明为static具有文件范围并且在文件本身之外不可见的内容。

你原来的错误:

undefined symbol `init_window_class_under'

发生是因为Window.cinit_window_class_under特别是)中的所有函数都是static并且static函数不会导致链接器找到任何符号。只有具有外部链接的实体才会在目标文件中产生符号。

于 2011-04-04T01:10:59.580 回答