如何在 MacPorts gcc 4.5 中调试 C++0x 程序? [英] How do I debug C++0x programs in MacPorts gcc 4.5?

查看:20
本文介绍了如何在 MacPorts gcc 4.5 中调试 C++0x 程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调试一个简单的 c++ 程序,但 gdb 找不到库的目标文件(或没有可用的调试信息),而且它似乎也无法找到我的可执行文件的调试符号.

I have a simple c++ program I am trying to debug, but gdb cannot find the object file for the libraries (or no debug info is available), and it does not seem able to find the debug symbols for my executable either.

我在 OSX 10.5.8 上,使用 macports,我用

I am on OSX 10.5.8, with macports, and I compile my code with

g++-mp-4.5 -Wall -pedantic -std=c++0x -g -ggdb -I/opt/local/include -L/opt/local/lib -lgsl-static-libstdc++ MCMC-simplex.cpp -o mcmc

g++-mp-4.5 -Wall -pedantic -std=c++0x -g -ggdb -I/opt/local/include -L/opt/local/lib -lgsl -static-libstdc++ MCMC-simplex.cpp -o mcmc

(只有一个文件,g++-mp-4.5是gcc/g++ 4.5的macports可执行文件)

(there is only one file, and g++-mp-4.5 is the macports executable for gcc/g++ 4.5 )

当我尝试在生成的可执行文件上运行 gdb 时,我收到许多表单的错误消息(在启动时)

When I try running gdb on the resulting executable, I get many error messages (at startup) of the form

警告:找不到目标文件/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_lang_gcc45/work/build/i386-apple-darwin9/libgcc/trunctfdf2_s.o" - 没有可用的调试信息../../../gcc-4.5.0/libgcc/../gcc/config/soft-fp/trunctfdf2.c".

warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_lang_gcc45/work/build/i386-apple-darwin9/libgcc/trunctfdf2_s.o" - no debug information available for "../../../gcc-4.5.0/libgcc/../gcc/config/soft-fp/trunctfdf2.c".

这对我来说表明 macports 在构建过程中存在错误(似乎 gdb 正在临时构建目录中寻找目标文件).

which to me indicates that macports has a bug during its build (it seems like gdb is looking for the object files in the temporary build directory).

我应该补充一点,当我尝试在 gdb(Apple 提供的那个)中查看我的程序时,它会尝试在 /var/tmp 中查找随机的 .s 文件,对我来说这听起来像是一个汇编文件.这就是为什么我说它似乎也找不到我的程序的调试符号.

I should add that when I try to see my programs listing in gdb (the one provided by Apple), it tries to look for a random .s file in /var/tmp, which to me sounds like an assembler file. That is why I say it does not seem able to find the debug symbols for my program either.

当我尝试 MacPorts gdb 7.1 时,我得到了

When I try MacPorts gdb 7.1, I get

警告:`/var/folders/Xa/XaqHO9PeEC8K-Nrd0L9xWk+++TM/-Tmp-//cc2IvFto.o':无法打开以读取符号:没有这样的文件或目录.(未找到调试符号)...完成.

warning: `/var/folders/Xa/XaqHO9PeEC8K-Nrd0L9xWk+++TM/-Tmp-//cc2IvFto.o': can't open to read symbols: No such file or directory. (no debugging symbols found)...done.

Apple 的 gdb 给出的许多错误消息都没有(尽管最终结果是相同的).

and none of the many error messages that Apple's gdb gives out (although the end result is the same).

有没有人遇到过这个问题,并想出了解决方案?

Has anyone come across this problem, and came up with a solution?

推荐答案

好吧,另一个继续使用单个编译和链接步骤的技巧"是添加
-save-temps=obj
到你的 g++ 命令行,这样

Well, another "trick" to keep going with a single compile-and-link step would be to add
-save-temps=obj
to your g++ command line so that

4 删除/tmp/[random-string].o 和 .s

4 Remove /tmp/[random-string].o and .s

实际上有点不执行(实际上,您最终在要构建的目录中拥有规范的 SOURCE.o 和 SOURCE.s 文件,而不是在某些临时文件夹中的 RANDOM-STRING.[os] ,但来自定位调试符号的观点很好

is actually sort of not performed (actually you end up having the canonical SOURCE.o and SOURCE.s files in the directory where you're building instead of RANDOM-STRING.[os] in some temp folders, but from the point of view of locating debugging symbols that's fine

这篇关于如何在 MacPorts gcc 4.5 中调试 C++0x 程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆