C++ Compiler for mac.

Started by
26 comments, last by igni ferroque 18 years, 10 months ago
Quote:Original post by llamaSong
Quote:Original post by Boder
Are you giving up on Pygame?


No, I am looking for multiple paths. If both I can get pygame to work, I will use that, if I can get xcode to work, I will use that, if both work I will use pygame.


I tried to learn Common Lisp and C at the same time. It wasn't easy.
Advertisement
Quote:Original post by Ikana
Quote:Original post by llamaSong
Quote:Original post by Boder
Are you giving up on Pygame?


No, I am looking for multiple paths. If both I can get pygame to work, I will use that, if I can get xcode to work, I will use that, if both work I will use pygame.


I tried to learn Common Lisp and C at the same time. It wasn't easy.



No, you misunderstand me( Or I you) I would rather use python and pygame, so if both work I will be learning Python+pygame, if only c++ works I will learn that.
... I'm confused. Did you ever get it to work? What is the actual problem?

Quote:Heres what I did.
Open up xcode
File
New Project
C++ Tool
Project Name C++ Tool
Finish
Targets
Double Click C++Test.1
Short Sample of what came up:
Build Build and Go Tasks Fix Groups Project Editing Mode
.\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.
.\"See Also:
.\"man mdoc.samples for a complete listing of options
.\"man mdoc for the short list of editing options
.\"/usr/share/misc/mdoc.template

A file with a .1 extension sounds like a manpage to me.

Free Mac Mini (I know, I'm a tool)
Quote:Original post by llamaSong
Hey all. I am looking for a C++ Compiler for mac.
I have googled, C++ Compiler Mac, and the only ones that came up you have to pay for.
I also have the Developer set for which came on my mac, it has Xtools/code in it which I believe can Compile for C++, the problem is it is amazainly confusing and I have no clue what to do with it.

If any one can explain how to use Xtools/code to compile C++, or has a tutorial for xtools/code could you please let me know.

Also if anyone knows of a free mac compiler could you tell me.

Can't get much easier and faster than using gcc in terminal like I do on my mac.
try gcc -g -o hello hello.cpp to compile program
then type
./hello to run said program
It's pretty easy with xcode too just click on c++ tool template and it'll automatically create everything you need and just modify the main.cpp file to your liking and compile.
Like I said though I stick to command line since it's alot faster compiling programs on my powerbook 500mhz than going through xcode.

[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
OKay, so using Xcode, once the terminal comes up I put in this into the terminal?:

#include <iostream.h>
int main()
{
cout << "Hello, Houston\n";
return -1;
}

And then I hit run? and it should say Hello, Houston.
Or do I make a text file, with this code, save it as .cpp and then select it through xcode and run it?
Quote:Original post by llamaSong
OKay, so using Xcode, once the terminal comes up I put in this into the terminal?:

#include <iostream.h>
int main()
{
cout << "Hello, Houston\n";
return -1;
}

And then I hit run? and it should say Hello, Houston.
Or do I make a text file, with this code, save it as .cpp and then select it through xcode and run it?
What terminal? You mean the code editor? Also, the standard return code for success is 0 (and error codes greater than 0 are usually for failure).
Quote:
#include <iostream.h>int main(){    cout << "Hello, Houston\n";    return -1;}

Don't you mean...
#include <iostream>using namespace std;int main(){  cout << "Hello, Houston\n";  return 0;}


Quote:
Or do I make a text file, with this code, save it as .cpp and then select it through xcode and run it?

When you create a new C++ tool project, it will create a file called main.cpp with a main routine already defined. When you click 'Run' in the project window, it will display the output in a window called the Run Log. You can interact with the program through this window.
Free Mac Mini (I know, I'm a tool)
Quote:Original post by igni ferroque
Quote:
#include <iostream.h>int main(){    cout << "Hello, Houston\n";    return -1;}

Don't you mean...
#include <iostream>using namespace std;int main(){  cout << "Hello, Houston\n";  return 0;}


Quote:
Or do I make a text file, with this code, save it as .cpp and then select it through xcode and run it?

When you create a new C++ tool project, it will create a file called main.cpp with a main routine already defined. When you click 'Run' in the project window, it will display the output in a window called the Run Log. You can interact with the program through this window.


Thats a code I got off another site, they must have an error, ill try yours.

Quote:Original post by igni ferroque
Don't you mean...
#include <iostream>using namespace std;int main(){  cout << "Hello, Houston\n";  return 0;}




I think he means:
#include <iostream>using std::cout;using std::endl;int main() {   cout << "Hello, Houston" << endl;   return 0;}
- iostream.h is not proper C++. The standard name for the header is iostream

- In virtually every OS I've ever seen, -1 is an error code from main. Return 0 to indicate no-error. This is a good habit to get into, because failing to do this can screw up people who write shell scripts (or other methods) that call your programs.

- In standard C++, the std namespace is not automatically activated. Therefore you either need to use using namespace std; or qualify all use of std (e.g. std::cout rather than just cout). Generally it is preferred to qualify the use of std because wantonly activating namespaces can lead to name conflicts, and rather defeats the point of namespaces in the first place.

- There's also something neither code version got right: in C++, it is preferred to use std::cout::endl rather than '\n' or similar escape sequences. endl is more portable and guaranteed to produce the proper sequence. It is also guaranteed to properly flush the output buffer.


[edit] Beaten - jperalta's code is completely correct, aside from the horrid brace placement style [wink]

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement