【问题标题】:C++: compilation error - "no .eh_frame_hdr table will be created"C++:编译错误 - “不会创建 .eh_frame_hdr 表”
【发布时间】:2011-04-11 08:30:16
【问题描述】:

我应该使用数据分析程序进行物理实验。但我无法编译它。

代码很旧,与我能找到的当前 GCC 版本不完全兼容。为了让事情变得更耗时,我从一个修改了所有 makefile 以使其在 Mac 上编译的人那里获得了代码。我没有 C++ 经验,但是通过手册页、Google 和耐心,我已经修复了很多错误,但我仍然坚持这个错误,即使经过一周的尝试和谷歌搜索。

我相信相关的错误信息如下:

/usr/bin/ld: error in /home/daniel/skola/exjobb/miniballscripts
/lib/libCommandLineInterface.so(.eh_frame); no .eh_frame_hdr table will be created.`

可能是什么原因,有什么补救措施?

libCommandLineInterface.so是我之前编译的,没有任何明显的错误信息:

$ make  
g++ -g2 -O2 -I./ -c CommandLineInterface.cc -o CommandLineInterface.o  
g++ -g  -Wl -o /home/daniel/skola/exjobb/miniballscripts/lib/libCommandLineInterface.so
CommandLineInterface.o -lm -L/home/daniel/skola/exjobb/miniballscripts/lib -lgcc -lc  
Done

我的 g++ 版本是 g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3, amd64。

正如我所说,我没有使用 C++ 的经验,所以也许我天真的 Makefile 修改已经破坏了一些东西。我缺乏经验也让我不知道还需要哪些其他信息来帮助我,但我很乐意回复。

【问题讨论】:

    标签: c++ compilation linker ld


    【解决方案1】:

    关注的链接错误开始于:

    [...]/lib/libCommandLineInterface.so: In function `_start':
    (.text+0x0): multiple definition of `_start'
    /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o:(.text+0x0): first defined here
    [...]/lib/libCommandLineInterface.so: In function `_fini':
    (.fini+0x0): multiple definition of `_fini'
    /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crti.o:(.fini+0x0): first defined here
    [...]/lib/libCommandLineInterface.so:(.rodata+0x0): multiple definition of `_IO_stdin_used'
    /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
    [...]/lib/libCommandLineInterface.so: In function `__data_start':
    (.data+0x0): multiple definition of `__data_start'
    /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o:(.data+0x0): first defined here
    [...]/lib/libCommandLineInterface.so: In function `__data_start':
    (.data+0x8): multiple definition of `__dso_handle'
    /usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtbegin.o:(.data+0x0): first defined here
    [...]/lib/libCommandLineInterface.so: In function `_edata':
    (*ABS*+0x607130): multiple definition of `__bss_start'
    [...]/lib/libCommandLineInterface.so: In function `_end':
    (*ABS*+0x6073b8): multiple definition of `_end'
    [...]/lib/libCommandLineInterface.so: In function `_edata':
    (*ABS*+0x607130): multiple definition of `_edata'
    [...]/lib/libCommandLineInterface.so: In function `main':
    /home/daniel/skola/exjobb/miniballscripts/Common/CommandLineInterface.cc:6: multiple definition of `main'
    

    多重定义的符号在 Unix 上是“标准”的 - 我自己也从来不需要在 Mac 上打扰它们,尽管我不在那里进行 GUI 编程。

    您需要以非常偏见的态度看待libCommandLineInterface.cc,并决定它是否提供了您需要的任何东西。您也许可以完全删除它。如果它包含一些您确实需要的东西,您将需要烧灼定义_start_endmain 等的材料。

    您还将不得不担心丢失的 vtables:

    [...]/libTransfer.so: undefined reference to `vtable for Annular'
    [...]/libTransfer.so: undefined reference to `ROOT::GenerateInitInstance(Barrel const*)'
    [...]/libTransfer.so: undefined reference to `ROOT::GenerateInitInstance(Annular const*)'
    [...]/libTransfer.so: undefined reference to `vtable for Barrel'
    [...]/libTransfer.so: undefined reference to `vtable for Crystal'
    [...]/libTransfer.so: undefined reference to `vtable for Germanium'
    

    【讨论】:

    • 非常感谢您的回答。 eh_frame_hdr 问题已解决,现在是丢失的 vtable-messages。
    【解决方案2】:

    看起来您在生成libCommandLineInterface.so 文件时忘记了-shared 命令行选项。这可以解释那些多重定义错误。如果链接器认为它正在生成的文件是可执行文件(而不是动态库),那么它将链接到启动代码等。当您尝试使用此 .so 文件时,那些来自启动代码的符号将与那些被添加到使用动态库的可执行文件冲突。

    libTransfer.so 错误可能与省略相同的标志有关。共享库允许有悬空引用(在使用库时得到解析),但可执行文件必须在链接时解析所有符号。这可能是对事情的过度简化,但我从不需要深入了解 linux 中的动态链接的更多细节。 :) 无论如何,添加-shared 选项也可以解决未定义的引用错误。

    【讨论】:

    • 非常感谢,我需要在 libCommandLineInterface.so 的编译器命令中添加 -fPIC 和 -shared。现在我离我的目标又近了一步:-)
    • 忘了说:它没有修复未定义的引用,但它使 eh_frame_hdr-error 消失了。
    【解决方案3】:

    解决了。这个线程解决了 eh_frame_hdr 问题。通过在第一个make 之后删除libTransfer.so,然后直接再次运行make,解决了未定义的引用。不要问我是怎么做的,但这让它编译好了。

    【讨论】:

    • "这个线程解决了 eh_frame_hdr-problem..." - 如何或在哪里?我没有看到它在任何地方说明。
    • @jww:这是几年前的事了,但在对已接受答案的评论中,我写道-shared(显然是-fPIC)使eh_frame_hdr 消息消失了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多