C++:编译错误 - “不会创建 .eh_frame_hdr 表”

发布于 2024-09-18 14:33:00 字数 1161 浏览 2 评论 0原文

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

该代码很旧,与我能找到的当前 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++-version 是 g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3, amd64。

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

I'm supposed to use a data analysis program for a physics experiment. I can't get it to compile though.

The code is old, not really compatible with current GCC-versions from what I can find. To make things a bit more time-comsuming, I got the code from a guy who had modified all the makefiles to make it compile on Mac. I have no C++-experience, but with man-pages, Google and patience I have fixed a lot of errors on the way, but I'm stuck on this one, even after a week of tries and googling.

I believe the relevant error message is the following:

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

What can be the cause, and what can be the remedy?

libCommandLineInterface.so was compiled by me before, without any apparent error messages:

$ 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

My g++-version is g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3, amd64.

As I said, I have no experience with C++, so maybe my naive Makefile modifications have destroyed something. My lack of experience also makes me not really knowing what other information is needed to help me, but I'll be glad to reply.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

野心澎湃 2024-09-25 14:33:00

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

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

Looks like you have forgotten the -shared command line option when you generate the libCommandLineInterface.so file. That would explain those multiple definition errors. If the linker thinks that the file it is generating is an executable (instead of a dynamic library), then it would link in the startup code, etc. When you try to use this .so file, those symbols coming in from the startup code will clash with those that are being added to the executable that uses the dynamic library.

It is possible that the libTransfer.so errors are related to the same flag being omitted. A shared library is allowed to have dangling references (that get resolved when the library is used), but an executable has to have all the symbols resolved at link time. This is probably an oversimplification of how things are, but I never needed to get into more details on dynamic linking in linux. :) Anyhow, adding -shared option may solve the undefined reference errors as well.

黒涩兲箜 2024-09-25 14:33:00

值得关注的链接错误始于:

[...]/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 等的材料。

您还必须担心缺少的 vtable:

[...]/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'

The linking errors of concern start with:

[...]/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'

The symbols that are multiply defined are 'standard' on Unix - and I've never needed to bother with them myself on Mac either, though I don't do GUI programming there.

You need to look at libCommandLineInterface.cc with a very prejudiced attitude and decide whether it provides anything that you need. You might be able to remove it altogether. If it contains some stuff you do need, you will need to cauterize the material that defines _start, and _end and main and so on.

You are also going to have to worry about the missing 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'
风为裳 2024-09-25 14:33:00

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

It's solved. The eh_frame_hdr-problem was solved by this thread. The undefined references was solved by deleting libTransfer.so after the first make, and then directly afterwards running make again. Don't ask me how, but that made it compile.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文