在linux上链接时出现“不可代表的输出部分”错误

时间:2009-10-05 19:13:03

标签: c++ linux linker-errors

在我的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调用中持续存在的一致行为。

3 个答案:

答案 0 :(得分:6)

我在收到ARM的交叉编译时收到了“关于输出的不可代表的部分”错误,并且某些库未使用-fPIC正确编译。 很确定这不是错误,但是......

答案 1 :(得分:4)

我的回答特定于hidden symbol (...) is referenced by DSONonrepresentable section on output错误的组合。

简短回答是:符号已标记为extern,但也标记为隐藏(请参阅Visibility (GCC wiki)How To Write Shared Libraries (Ulrich Drepper))。没有链接任何对象或存档来满足依赖关系,但共享对象 与匹配的符号链接。

您可能使用-fvisibility=hidden进行编译,无论是编译器添加的功能(如堆栈保护程序)还是完全不同的东西,代码中发出的符号都会覆盖相同的未定义符号引用的默认可见性libc_nonshared.a中通常由libc.so满足的#include <stdio.h> extern __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

...然后编译它:

#if

简而言之:我前进声明了符号的存在,将其标记为隐藏,然后没有链接到满足依赖关系的静态库或目标文件中。由于它被标记为隐藏,因此必须满足依赖,否则它将成为无效的ELF对象。

在我的具体情况中,标题位于错误的open_memstream路径下,并导致上述隐藏的git reflog声明。

答案 2 :(得分:3)

请尝试从命令行中删除-fvisibility = hidden选项。它会产生一个更大的对象(带有一些不必要的符号,最终无关紧要,因为它是一个可执行的),但应该消除这个问题。这不是解决方案;而是一种解决方法。如果库和GtkLauncher.o之间没有libc版本不匹配,请检查(这只是预感)