简体   繁体   English

包括在MacOS上使用g ++编译时找不到的路径

[英]Include paths not found while compiling with g++ on MacOS

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 where can I find the include directories and how can 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. 我刚刚安装了XCode 3.1.4,并设法通过Xcode而不是通过命令行对其进行了编译。 I found some header files in this directory: 我在此目录中找到了一些头文件:

/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 this question, 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. 我正在Linux上进行开发,并且在那里一切正常,但是我想在MacOS上继续这样做。 Any help? 有什么帮助吗?

On my Mac, that include file is in /usr/include/c++/4.0.0/iostream . 在我的Mac上,该包含文件位于/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. 我很确定第一次安装Mac时必须手动安装它。 There should be a "developer tools" package somewhere on your OS X installation media. 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

$ 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM