xcode 在 MacOS 上使用 g++ 编译时包含未找到的路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2114127/
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
Include paths not found while compiling with g++ on MacOS
提问by Lipis
I'm trying to compile the simplest program on MacOS 10.6 like:
我正在尝试在 MacOS 10.6 上编译最简单的程序,例如:
$ g++ -o hello hello.cpp
the following source:
以下来源:
#include <iostream>
int main (int argc, char * const argv[]) {
std::cout << "Hello, World!\n";
return 0;
}
I'm getting the error:
我收到错误:
hello.cpp:1:20: error: iostream: No such file or directory
hello.cpp: In function ‘int main(int, char* const*)':
hello.cpp:4: error: ‘cout' is not a member of ‘std'
So obviously I have to add the include path somewhere. My question is wherecan I find the include directories and howcan add them globally (I don't want to provide the include path whenever I want to compile).
所以显然我必须在某处添加包含路径。我的问题是我在哪里可以找到包含目录以及如何全局添加它们(我不想在我想编译时提供包含路径)。
I just installed the XCode 3.1.4 and managed to compile it via Xcode, but not via command line. I found some header files in this directory:
我刚刚安装了 XCode 3.1.4 并设法通过 Xcode 编译它,但不是通过命令行。我在这个目录中找到了一些头文件:
/Xcode3.1.4/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers
and tried to add it to the HEADER_SEARCH_PATHS after reading thisquestion, but no luck.
并在阅读此问题后尝试将其添加到 HEADER_SEARCH_PATHS 中,但没有运气。
I'm developing on Linux and everything is working fine there, but I want to continue doing that on MacOS. Any help?
我正在 Linux 上开发,一切正常,但我想在 MacOS 上继续这样做。有什么帮助吗?
采纳答案by Jim Lewis
On my Mac, that include file is in /usr/include/c++/4.0.0/iostream . Are you sure you have all the command-line development tools installed? They might not be by default; I'm pretty sure I had to install it manually when I first set up my Mac. There should be a "developer tools" package somewhere on your OS X installation media.
在我的 Mac 上,该包含文件位于 /usr/include/c++/4.0.0/iostream 中。你确定你安装了所有的命令行开发工具吗?它们可能不是默认的;我很确定我第一次设置 Mac 时必须手动安装它。您的 OS X 安装媒体上应该有一个“开发人员工具”包。
Or, if you want to make sure you're getting the latest version, you can download it from: http://developer.apple.com/technology/xcode.html
或者,如果您想确保获得最新版本,可以从以下网址下载:http: //developer.apple.com/technology/xcode.html
回答by adriano
$ g++ -o example.bin example.cpp //to compile
$ ./example.bin //to run
It's code:
它的代码:
#include <iostream>
using namespace std;
int main () {
cout << "Hello, World!\n";
return 0;
}