我在OS X上运行gprof
时遇到了问题。文件test.c
是:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
我的终端看起来像这样:
$ gcc -pg test.c
$ gcc -pg -o test test.c
$ ./test
Hello, World!
$ gprof test
gprof: file: test is not of the host architecture
编辑:而且,它不会生成文件gmon.out
。
这里发生了什么事?
发布于 2009-07-08 19:11:46
这里的一系列事件的工作原理如下:
-pg
选项编译代码-pg
选项链接代码gmon.out
文件<代码>H211<代码>H112运行gprof
问题是第四步永远不会发生。关于这个特定故障的信息非常少。过去几年的普遍共识似乎是,苹果更愿意使用shark,而且他们在修复bug等问题上一直非常松懈,使用gprof
。
简而言之:安装Xcode、man shark
发布于 2009-07-08 19:07:38
不幸的是,gprof
不能在Mac上运行,您可能希望使用Shark
。它是/Developer/Applications/Performance Tools/Shark
中开发人员工具的一部分。
更新:似乎gprof
现在正在使用最新的开发工具在MacOSX10.6(雪豹)上工作。
发布于 2009-07-08 19:05:58
这听起来像是使用了gprof
没有预料到的架构来构建test
。尝试以下操作:
$ cat > test2.c
#include <stdio.h>
int main() { printf("test\n"); return 0; }
^D
$ gcc -arch i386 -pg -o test2 test2.c
$ file test2
test2: Mach-O executable i386
$ ./test2
test
$ gprof test2
... bunch of output ...
$ gcc -arch ppc -pg -o test2 test2.c
$ file test2
test: Mach-O executable ppc
$ ./test2
test
$ gprof test2
gprof: file: test2 is not of the host architecture
$ arch -ppc gprof test2
... same bunch of output ...
较新的MacOS支持从IBM PPC和英特尔x86体系结构运行可执行文件。一些工具链似乎对此有点敏感。Gprof似乎希望可执行文件位于本机架构中。但是,如果您使用arch
实用程序强制执行非本机体系结构,那么它似乎可以正常工作。不久前有一个discussion about this in another context。我在那里包含了一些有用的链接和更多信息。
https://stackoverflow.com/questions/1101545
复制相似问题