Include paths not found when compiling with g ++ on MacOS

I am trying to compile a simple program on MacOS 10.6, for example:

$ g++ -o hello hello.cpp 

following source:

 #include <iostream> int main (int argc, char * const argv[]) { std::cout << "Hello, World!\n"; return 0; } 

I get an error message:

 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' 

Therefore, obviously, I need to add the include path somewhere. My question is: where can I find include directories and how can I add them globally (I don’t want to specify an include path when I want to compile). p>

I just installed Xcode 3.1.4 and was able to compile it using Xcode, but not through the command line. I found several 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 HEADER_SEARCH_PATHS after reading this question, but no luck.

I am working on Linux and everything works fine there, but I want to continue to do this on MacOS. Any help?

+4
source share
2 answers

On my Mac, this included file is in / usr / include / c ++ / 4.0.0 / iostream. Are you sure you have all the command line development tools installed? They may not be the default; I'm sure I had to install it manually when I first installed my Mac. Your OS X installation media must have the "developer tools" package.

Or, if you want to make sure you get the latest version, you can download it from: http://developer.apple.com/technology/xcode.html

+2
source
 $ g++ -o example.bin example.cpp //to compile $ ./example.bin //to run 

The code:

 #include <iostream> using namespace std; int main () { cout << "Hello, World!\n"; return 0; } 
-4
source

Source: https://habr.com/ru/post/1299057/


All Articles