4
votes

On one of my Mac box, for simple Hello Word C++ program, there are such compile error, other Macs I am working on are ok. Using even the same version of Eclipse CDT 64-bit Mars.

Posted error and Hello Word program, does anyone have any hints? Thanks.

//============================================================================
// Name        : Test1.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

enter image description here enter image description here

Attach error from g++ of command line,

g++ Test1.cpp Test1.cpp:9:20: error: iostream: No such file or directory Test1.cpp: In function ‘int main()’: Test1.cpp:13: error: ‘cout’ was not declared in this scope Test1.cpp:13: error: ‘endl’ was not declared in this scope

1
can you compile it from the terminal? e.g. g++ -o hello hello.cpp and then run it? ./hello If so, can you get detailed output of the commands that eclipse is running?Bill
Have you installed xcode?Bill
XCode does not come by default on the Mac, you have to go to the app store. Installing XCode also gives you C/C++ compilers, libraries, headers, useful tools like git, etc...Bill
No, it includes C, C++, ObjC, and Swift. According to this stackoverflow.com/questions/9315386/… The person switched to an older version of Eclipse. Although I wouldn't waste my time w/Eclipse for C++ development. Also, when compiling your program in the Terminal, you should cd to the directory where your program is and then try to compile it.Bill
@Bill, thanks and tried XCode works good to me. If you could summarize your reply, I will mark it as answer to benefit other people. :)Lin Ma

1 Answers

1
votes

In summary, if whether you're developing in C, C++ or Objective C on the Mac, you probably just want to use XCode.

Not sure what Eclipse was doing, but (see link in comments) earlier versions of Eclipse might work where later ones will not.