开发者

Ruby extension link error

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜