在我的Ubuntu 9.04盒子上编译webkit-1.1.5包时,我在链接器阶段得到了这个错误:
libtool: link: gcc -ansi -fno-strict-aliasing -O2 -Wall -W -Wcast-align -Wchar-subscripts -Wreturn-type -Wformat -Wformat-security -Wno-format-y2k -Wundef -Wmissing-format-attribute -Wpointer-arith -Wwrite-strings -Wno-unused-parameter -Wno-parentheses -fno-exceptions -fvisibility=hidden -D_REENTRANT -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libsoup-2.4 -I/usr/include/libxml2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -g -O2 -O2 -o Programs/.libs/GtkLauncher WebKitTools/GtkLauncher/Programs_GtkLauncher-main.o -pthread ./.libs/libwebkit-1.0.so /usr/lib/libgtk-x11-2.0.so /usr/lib/libgdk-x11-2.0.so /usr/lib/libatk-1.0.so /usr/lib/libpangoft2-1.0.so /usr/lib/libgdk_pixbuf-2.0.so -lm /usr/lib/libpangocairo-1.0.so /usr/lib/libgio-2.0.so /usr/lib/libcairo.so /usr/lib/libpango-1.0.so /usr/lib/libfreetype.so -lfontconfig /usr/lib/libgmodule-2.0.so /usr/lib/libgobject-2.0.so /usr/lib/libgthread-2.0.so -lrt /usr/lib/libglib-2.0.so -pthread make[1]: Leaving directory `/home/nagul/build_area/webkit-1.1.5' WebKitTools/DumpRenderTree/gtk/TestNetscapePlugin/TestNetscapePlugin.cpp: In function ‘NPError webkit_test_plugin_get_value(NPP_t*, NPPVariable, void*)’: WebKitTools/DumpRenderTree/gtk/TestNetscapePlugin/TestNetscapePlugin.cpp:221: warning: deprecated conversion from string constant to ‘char*’ WebKitTools/DumpRenderTree/gtk/TestNetscapePlugin/TestNetscapePlugin.cpp:224: warning: deprecated conversion from string constant to ‘char*’ WebKitTools/DumpRenderTree/gtk/TestNetscapePlugin/TestNetscapePlugin.cpp: In function ‘char* NP_GetMIMEDescription()’: WebKitTools/DumpRenderTree/gtk/TestNetscapePlugin/TestNetscapePlugin.cpp:260: warning: deprecated conversion from string constant to ‘char*’ /usr/bin/ld: Programs/.libs/GtkLauncher: hidden symbol `__stack_chk_fail_local' in /usr/lib/libc_nonshared.a(stack_chk_fail_local.oS) is referenced by DSO /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: ld returned 1 exit status make[1]: *** [Programs/GtkLauncher] Error 1 make: *** [all] Error 2
我想通过查看"隐藏的sybmol"错误或者通过帮助我理解链接器中的"不可表示的输出部分"消息实际意味着如何来解决这个问题.
我已经检查过这是在make clean;make
调用中持续存在的一致行为.
我在收到ARM的交叉编译时收到了"关于输出的不可代表的部分"错误,并且某些库未使用-fPIC正确编译.很确定这不是错误,但......
我的答案特定于hidden symbol (...) is referenced by DSO
和Nonrepresentable section on output
错误的组合。
简短的答案是:标记了一个符号,extern
但也标记了它为隐藏的(请参见“ 可见性”(GCC Wiki)和“ 如何编写共享库”(Ulrich Drepper))。没有对象或归档在被链接到满足的依赖性,但共享对象物在与匹配的符号链接。
您可能使用-fvisibility=hidden
进行了编译,而无论它是添加了编译器的功能(例如堆栈保护器)还是其他全部功能,代码中发出的符号都会覆盖未定义的同名符号引用的默认可见性,libc_nonshared.a
通常可以满足以下要求:libc.so
。
您可以重现类似的问题,如下所示:
#includeextern __attribute__((visibility ("hidden"))) FILE* open_memstream( char**, size_t* ); char* asdf; size_t mysize; FILE* blah() { return open_memstream( &asdf, &mysize ); }
...然后编译它:
# with gcc 4.9.2: ~ gcc badcode.c -shared -fPIC -o libbad.so -lc /tmp/ccC0uG80.o: In function `blah': badcode.c:(.text+0x19): undefined reference to `open_memstream' /usr/bin/ld: /tmp/libbad.so: hidden symbol `open_memstream' isn't defined /usr/bin/ld: final link failed: Bad value # with gcc 4.4.7: ~ gcc badcode.c -shared -fPIC -o libbad.so -lc /tmp/cc2SHUFD.o: In function `blah': badcode.c:(.text+0x26): undefined reference to `open_memstream' /usr/bin/ld: /tmp/libbad.so: hidden symbol `open_memstream' isn't defined /usr/bin/ld: final link failed: Nonrepresentable section on output # with oracle solaris studio (still in Linux) 12.3: ~ cc -shared -Kpic -o /tmp/libbad.so badcode.c -lc badcode.o: In function `blah': badcode.c:(.text+0x32): undefined reference to `open_memstream' /usr/bin/ld: /tmp/libbad.so: hidden symbol `open_memstream' isn't defined /usr/bin/ld: final link failed: Nonrepresentable section on output
简而言之:我向前声明了一个符号的存在,将其标记为隐藏,然后没有链接到满足依赖性的静态库或目标文件中。由于已将其标记为隐藏,因此必须满足依赖关系,否则它是无效的ELF对象。
在我的特定情况下,标头沿错误的#if
路径运行并导致上述的隐藏声明open_memstream
。
请尝试从命令行中删除-fvisibility = hidden选项。它将产生一个更大的对象(带有一些不必要的符号,最终将不会有什么问题,因为它是可以执行的),但是应该可以解决该问题。这不是解决方案。而是一种解决方法。请检查(这只是预感)在库和GtkLauncher.o之间是否没有libc版本不匹配