我在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
。
这里发生了什么?
答案 0 :(得分:9)
这里的一系列事件应该如下工作:
-pg
选项-pg
选项gmon.out
文件gprof
问题是第4步永远不会发生。关于这一具体失败的信息非常少。过去几年普遍的共识似乎是苹果宁愿使用鲨鱼,而且他们在修复错误方面非常松懈等等gprof
。
简而言之:安装Xcode,man shark
答案 1 :(得分:4)
不幸的是gprof
在Mac OS X上不起作用。您可能希望改用Shark
。它是/Developer/Applications/Performance Tools/Shark
中的开发人员工具的一部分。
更新:好像gprof
正在使用最新的开发者工具在Mac OS X 10.6(Snow Leopard)上运行。
答案 2 :(得分:3)
听起来test
是使用gprof
不期望的架构构建的。请尝试以下方法:
$ 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和Intel x86架构运行可执行文件。一些工具链似乎对此有点密集。 Gprof似乎期望可执行文件在本机架构中。但是,如果使用arch
实用程序强制执行非本机体系结构,则它似乎正常工作。不久前有一个discussion about this in another context。我在那里提供了一些有用的链接和更多信息。