macos OS X 上的 gprof 问题:[程序] 不属于主机架构
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1101545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Problem with gprof on OS X: [program] is not of the host architecture
提问by Jesse Beder
I'm having trouble running gprof
on OS X. The file test.c
is:
我gprof
在 OS X 上运行时遇到问题。文件test.c
是:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
and my terminal looks like:
我的终端看起来像:
$ gcc -pg test.c
$ gcc -pg -o test test.c
$ ./test
Hello, World!
$ gprof test
gprof: file: test is not of the host architecture
Edit: also, it doesn't generate the file gmon.out
.
编辑:此外,它不会生成文件gmon.out
.
What's going on here?
这里发生了什么?
采纳答案by Curtis Tasker
The series of events here is supposed to work as follows:
这里的一系列事件应该如下工作:
- Compile code with
-pg
option - Link code with
-pg
option - Run program
- Program generates
gmon.out
file - Run
gprof
- 使用
-pg
选项编译代码 - 带
-pg
选项的链接代码 - 运行程序
- 程序生成
gmon.out
文件 - 跑
gprof
The problem is that step 4 never happens. There's very little information out about this specific failure. The general consensus over the past few years seems to be that Apple would rather use shark instead, and they've been very lax about fixing bugs and such with gprof
.
问题是第 4 步永远不会发生。关于此特定故障的信息很少。过去几年的普遍共识似乎是,Apple 更愿意使用shark 来代替,而且他们在使用gprof
.
In short: Install Xcode, man shark
简而言之:安装Xcode, man shark
回答by mark4o
Unfortunately gprof
does not work on Mac OS X. You'll probably want to use Shark
instead. It is part of the developer tools in /Developer/Applications/Performance Tools/Shark
.
不幸的是,gprof
它不适用于 Mac OS X。您可能想Shark
改用它。它是/Developer/Applications/Performance Tools/Shark
.
Update:It appears as though gprof
is now working on Mac OS X 10.6 (Snow Leopard), using the latest Developer Tools.
更新:看起来好像gprof
现在正在使用最新的开发人员工具在 Mac OS X 10.6 (Snow Leopard) 上工作。
回答by D.Shawley
It sounds like test
is built using an architecture that gprof
doesn't expect. Try the following:
听起来像是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 ...
The newer MacOS supports running executables from either the IBM PPC and Intel x86 architecture. Some of the tool chain seems to be a bit dense about this. Gprof seems to expect the executable to be in the native architecture. However, if you use the arch
utility to force the non-native architecture to be executed, then it seems to work properly. There was a discussion about this in another contexta little while ago. I included some useful links and some more information there.
较新的 MacOS 支持运行来自 IBM PPC 和 Intel x86 架构的可执行文件。一些工具链似乎对此有点密集。Gprof 似乎希望可执行文件位于本机架构中。但是,如果您使用该arch
实用程序强制执行非本机架构,那么它似乎可以正常工作。有一个在另一语境中的讨论一会儿前。我在那里包含了一些有用的链接和更多信息。