问题描述
我正在使用Mac OSX 10.8.5版本(Mountain Lion?)。
main.cpp:
#include< iostream>
int main()
{
std :: cout<< Hello world!<< std :: endl;
std :: cout<< 再见的世界!<< std :: endl;
返回0;
}
我试图让gprof在我的电脑上工作。如所示,我输入以下内容两行代码到我的终端:
g ++ -g -pg main.cpp -o a.out
./a .out
然而,这并不会像它应该生成的gmon.out文件一样。当我尝试在终端上输入gprof时,它说:
gprof:无法打开:gmon.out(No这样的文件或目录)
由于gmon.out不存在
关于我在做什么的任何想法都是错误的?
编辑:其他一些可能有用的东西:
- 我有一个类似OS X版本的朋友(我可以稍后再问他确认),和g ++和gprof完全相同的版本能够使用gprof正如我已经概述的那样。
- 我使用的是旧版本的g ++,但是我在线阅读过更新到新版本并没有帮助...
-a.out完美地工作,它打印出Hello world!和再见的世界!。我也尝试过用更复杂的C ++程序和几个类,它仍然有同样的问题。一切正常,编译和运行正常,但没有产生gmon.out文件。
您必须认识到,OS X / MacOS不会在系统上默认提供GNU GCC。
请注意以下命令的输出:
ls -la / usr / bin / g ++ / usr / bin / clang ++
这些可执行文件看起来相同(实际上,它们看起来不一样,但不知何故文件大小是一样的!)
据我所知,clang不支持gprof输出的生成。尽管可能会引起混淆,但是 gcc
程序将运行clang。
我建议尝试使用自制软件在OS X / MacOS上安装GCC。你确实要小心它的安装方式等,以便你知道哪个命令对应哪个编译器。
I'm running on Mac OSX, version 10.8.5 (Mountain Lion?). I have the following simple C++ code.
main.cpp:
#include <iostream>
int main ()
{
std::cout << "Hello world!"<<std::endl;
std::cout << "Goodbye world!"<<std::endl;
return 0;
}
I'm trying to get gprof to work on my computer. As the manual suggests, I enter the following two lines into my terminal:
g++ -g -pg main.cpp -o a.out
./a.out
However this does not generate a gmon.out file as it is supposed to. When I try typing "gprof" in the terminal, it says:
gprof: can't open: gmon.out (No such file or directory)
which is to be expected since gmon.out isn't there...
Any ideas on what I'm doing wrong?
EDIT: Some other things that may help:
-My friend, who has a similar OS X version (I can ask him later to confirm), and the exact same versions of g++ and gprof, was able to use gprof successfully as I have outlined.
-I'm using an older version of g++ but I have read online that updating to a newer version didn't help...
-a.out works perfectly, it prints out "Hello world!" and "Goodbye world!". I also tried this with a more complex C++ program with several classes and it still has the same problem. Everything compiles and runs normally but no gmon.out file is produced.
You have to realize that OS X/MacOS does not provide GNU GCC on the system by default.
Note the output of this command:
ls -la /usr/bin/g++ /usr/bin/clang++
These executables look identical. (Actually! It looks like they are different, but somehow the filesize is identical!)
As far as I can tell, clang doesn't support the production of gprof output. As confusing as it may be, the gcc
program will run clang.
I would recommend trying to use homebrew to install GCC on OS X/MacOS. You do want to be careful about how it gets installed, etc., so that you know which command corresponds to which compiler.
这篇关于当我使用g ++编译-pg标志时,gmon.out不会被创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!