macos 如何从我的 Mac 上的终端窗口运行 g++
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4403253/
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
How to run g++ from a terminal window on my Mac
提问by ragnarius
I have a simple C++ program that I can compile (g++ from command line) and run from my work-computer but not from my home-computer. I don't know how they differ! They are both macbooks and I have installed iPhone SDK on both.
我有一个简单的 C++ 程序,我可以编译(从命令行使用 g++)并在我的工作计算机上运行,但不能从我的家用计算机上运行。不知道有什么区别!它们都是 macbook,我都安装了 iPhone SDK。
On my home-computer: When I add /Developer/usr/bin
to my PATH
I can run g++ but it cannot include <string>
and it does not recognize printf
and such functions. What else do I need to do to make g++ work?
在我的家用计算机上:当我添加/Developer/usr/bin
到我的计算机时,我PATH
可以运行 g++,但它不能包含<string>
并且无法识别printf
此类功能。我还需要做什么才能使 g++ 工作?
回答by Mircea Prodan
- Install xCode and then close
- Edit your c++ code file (I use Smultron, it is free and good)
- Save your file on Desktop with "cpp" termination
- Suppose you have test.cpp program
- Open Terminal (Applications -> Utilities)
- Change directory with command: cd Desktop
- Now write: g++ test.cpp -o test
- For run your program, in Terminal type: test (only that, without ending cpp!)
- If your program it is well writen, on the desktop appear a new file named test
- Click on it and you have your program running
- That is all!
- 安装 xCode 然后关闭
- 编辑你的 C++ 代码文件(我使用 Smultron,它是免费的而且很好)
- 使用“cpp”终止将文件保存在桌面上
- 假设你有 test.cpp 程序
- 打开终端(应用程序 -> 实用程序)
- 使用命令更改目录:cd Desktop
- 现在写: g++ test.cpp -o test
- 要运行您的程序,请在终端中键入:test(仅此而已,不结束 cpp!)
- 如果你的程序写得很好,桌面上会出现一个名为 test 的新文件
- 单击它,您的程序就会运行
- 就这些!
回答by Stuart Golodetz
When you installed Xcode and the iPhone SDK, did you check the box for Unix Development Support? I had a lot of problems with this sort of thing because I didn'tdo that, and the solution was to uninstall the SDK and start again with the box checked.
当您安装 Xcode 和 iPhone SDK 时,您是否选中了 Unix Development Support 复选框?我在这类事情上遇到了很多问题,因为我没有这样做,解决方案是卸载 SDK 并重新开始,选中该框。