C++ Compiler for mac.

This topic is 4614 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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.

Share on other sites
I believe OSX distributions come with GCC (which is what Xcode uses under the surface). You should be able to use a terminal window and autotools to do a *nix-style build setup, but that's arguably not any less confusing than Xcode [wink]

A good way to get started with Xcode is to create a new "C++ Tool" project. It will at least show you how the IDE expects things to be layed out. All of the compiler settings (well, in theory all of them, but I suspect many are missing) can be found by double-clicking the name of a target in the Targets area on the project viewer.

Unfortunately I don't know of any good documentation for Xcode. It's a steaming pile of crap and easily one of the worst-designed IDEs I've ever had the misfortune of using. Apple's developer site has some handy reference material and mailing lists, though.

Share on other sites
Quote:
 Original post by ApochPiQI believe OSX distributions come with GCC (which is what Xcode uses under the surface). You should be able to use a terminal window and autotools to do a *nix-style build setup, but that's arguably not any less confusing than Xcode [wink]A good way to get started with Xcode is to create a new "C++ Tool" project. It will at least show you how the IDE expects things to be layed out. All of the compiler settings (well, in theory all of them, but I suspect many are missing) can be found by double-clicking the name of a target in the Targets area on the project viewer.Unfortunately I don't know of any good documentation for Xcode. It's a steaming pile of crap and easily one of the worst-designed IDEs I've ever had the misfortune of using. Apple's developer site has some handy reference material and mailing lists, though.

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.
.\"man mdoc.samples for a complete listing of options
.\"man mdoc for the short list of editing options
.\"/usr/share/misc/mdoc.template

Share on other sites
Are you giving up on Pygame?

Share on other sites
Quote:
 Original post by BoderAre 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.

Share on other sites
I use XCode personally.
Here is how to set up a simple C++ project:

1) File, New Project, C++ Tool

This will create a basic C++ program that uses the stdc++ library

2) Name it, and put it in a directory.

If you "Build and Go" now, it should work, and a terminal window with "Hello, World!" should come up.

If you follow these directions, and it doesn't work, post what goes wrong.

Share on other sites
Quote:
 Original post by visageI use XCode personally.Here is how to set up a simple C++ project:1) File, New Project, C++ ToolThis will create a basic C++ program that uses the stdc++ library2) Name it, and put it in a directory.If you "Build and Go" now, it should work, and a terminal window with "Hello, World!" should come up.If you follow these directions, and it doesn't work, post what goes wrong.

So lets say I make a Hello World Code, but in stead, it Says Hello Houston, should the terminal then come up "Hello, World!" "Hello HOuston"?.

Share on other sites
Computers don't like to single groups out. They would much rather say hello to the entire world, instead of simply Houston.

Share on other sites
Quote:
 Original post by RDragon1Computers don't like to single groups out. They would much rather say hello to the entire world, instead of simply Houston.

lol

Share on other sites
Well, you will have a final called "projectname.cpp" where projectname is replaced by your project name. It contains the main() method within it, and that is where the "Hello World" code is defined. Change that file, or erase it and add a new file with a main method to make your own program.

Share on other sites
Quote:
Original post by llamaSong
Quote:
 Original post by BoderAre 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.

Share on other sites
Quote:
Original post by Ikana
Quote:
Original post by llamaSong
Quote:
 Original post by BoderAre 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.

Share on other sites
... I'm confused. Did you ever get it to work? What is the actual problem?

Quote:
 Heres what I did.Open up xcodeFileNew ProjectC++ ToolProject Name C++ ToolFinishTargetsDouble Click C++Test.1Short 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.

Share on other sites
Quote:
 Original post by llamaSongHey 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.

Share on other sites
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?

Share on other sites
Quote:
 Original post by llamaSongOKay, so using Xcode, once the terminal comes up I put in this into the terminal?:#include 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).

Share on other sites
Quote:
 #include 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.

Share on other sites
Quote:
Original post by igni ferroque
Quote:
 #include 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.

Share on other sites
Quote:
 Original post by igni ferroqueDon't you mean...#include 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;}

Share on other sites
- 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.

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

Share on other sites
Quote:
 Original post by ApochPiQ...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.
Uh, no.

First, it's std::endl, as endl is a manipulator and a member of the std namespace, not a member of some class or namespace "cout" (cout is also an object).

Second, endl is not "preferred" to \n. Its meaning is equivalent to inserting a newline and then flushing the stream, and it should only be used when both actions are desired. You can insert newlines when that's all you want, or you can flush the stream if that's all you want (insert std::flush).

Happy hacking.

Share on other sites
Oops... std::cout::endl was a brain fart. Thanks.

Good point on flushing the stream as well. Generally though it's my experience that newbies tend to expect a stream flush, which is why I didn't mention the semantics. In some cases this can be a performance issue when making heavy use of stream objects, which should probably be kept in mind during implementation.

However it's worth noting that endl is guaranteed to use the locally preferred \n vs. \r\n vs. \r line break formatter, which is not so much important with cout but can become important for file I/O.

Share on other sites
Quote:
 I think he means:#include using std::cout;using std::endl;

Oh come now that's just crossing the line.
Quote:
 cout << "Hello, Houston" << endl;

Yeah, I caught that after I hit submit and didn't feel like replacing the angle brackets on the edit screen.

Share on other sites
Quote:
Original post by igni ferroque
Quote:
 I think he means:#include using std::cout;using std::endl;

Oh come now that's just crossing the line.
Quote:
 cout << "Hello, Houston" << endl;

Yeah, I caught that after I hit submit and didn't feel like replacing the angle brackets on the edit screen.

Okay, we are getting a bit off topic. The one thing I need to know is how to enter a code, then run it and get a resualt.

Share on other sites
Command-B builds, Command-R runs and builds (if it wasn't already built). Also, you can add more files to the project (just so you know).