Mac C++ Compiler for Mac? HELP with xcode?

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
So I'm totally new to the mac community (got my macbook pro for xmas) and now the semester has started again and Im registered in a first year math course -- introduction to computing with c++. now you guys can probably see where this is going.

basically, I hadone class and my professor gave us a linkto download a c++ compiler for windows, and I emailed him asking about one for Mac, and he told me I would have to search the internet for one as he has no experience with mac. so i did some searching and determined i should download xcode? NOW im still downloading it, but im fairly certain i wont be able to work it. im not a computer programming person, im only taking this course to satisfy my math credit requirements, but i do think it is something i may enjoy once i learn it. im really confused, and my prof wrote the textbook we use himself so i dont really find it to be much help. Honestly, any help would be greatly appreciated.

Thanks.
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
Technically I dont think it would be considered a textbook, its binded by my university and says "Math 1116 - Introduction to Computing with C++ Lecture Notes". So you're saying I don't need xcode? I'm so confused, I swear I'm not dumb but this topic is so new to me and quite confusing :(

also, would it just be "OS X 10.7 Lion: GCC-10.7.pkg" that I download from that link?
 

balamw

Moderator
Staff member
Aug 16, 2005
19,368
974
New England
Presuming you are running Lion ;)

It really depends on how the examples are described and set up. If it is really fine tuned for Visual C++ you may find doing it on the Mac more difficult.

B
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
Presuming you are running Lion ;)

B
Yes I am! I actually got something correct tonight. Lol my "homework" per se was to run a code given to us by my prof (shown below) in the compiler to make sure we can do it. so once i get this downloaded (unfortunately will take forever since I am on residence wireless) -- what should my next step be? if anyone is willing to explain that is :)

Code:
#include <iostream>

int main( )
{
   std::cout << "Hello world!\n";
   return 0;
}


----------

I suppose I could always just use the windows PCs at the library, but that is such a hassle if I could find out how to do it on my mac instead!
 
Last edited by a moderator:

lloyddean

macrumors 65816
May 10, 2009
1,002
16
Des Moines, WA
Xcode is a development environment. It includes a Text Editor (for writing source code), a C/C++ and ObjectiveC/C++ compiler, a linker and more.

Go ahead and download Xcode. You need the all the compiler and linker no matter what. But you maybe able to get by without learning the IDE, Integrated Development Environment that Xcode also provides.

CHeck back when you start programming you'll get plenty of help going from there.
 

chown33

Moderator
Staff member
Aug 9, 2009
8,562
4,635
inter-prandial
Having the title of the text book in question will affect the help provided here.
As would knowing which C++ compiler the prof told the Windows users to download. It's unclear to me whether it's a command-line C++ compiler, a simple GUI/IDE, or a full-featured GUI/IDE.

Context is important, and knowing exactly what the prof expects students to use is an important part of the context.
 

balamw

Moderator
Staff member
Aug 16, 2005
19,368
974
New England
Great!

Any chance you could give us some context for that code. This is a fairly typical first step, but it would help to see how your prof surrounds it.

Please wrap any code snippets in CODE tags using the hash mark # button in the edit window.

B
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
As would knowing which C++ compiler the prof told the Windows users to download. It's unclear to me whether it's a command-line C++ compiler, a simple GUI/IDE, or a full-featured GUI/IDE.

Context is important, and knowing exactly what the prof expects students to use is an important part of the context.
The file name was VC2005.exe, so im assuming microsoft visual c++? that's what came up when i googled it.
im starting to think im over my head in this.

----------

Great!

Any chance you could give us some context for that code. This is a fairly typical first step, but it would help to see how your prof surrounds it.

Please wrap any code snippets in CODE tags using the hash mark # button in the edit window.

B
Um it's just the first example we were given, all it says concerning it is that the output should be Hello world! Not much else is given.
 

balamw

Moderator
Staff member
Aug 16, 2005
19,368
974
New England
The file name was VC2005.exe, so im assuming microsoft visual c++? that's what came up when i googled it.
im starting to think im over my head in this.
Don't Panic. At this level you'll be fine.

It would have been much worse if the "Hello World!" example used a Windows specific dialog box mechanism. (Don't read this).

B
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
Don't Panic. At this level you'll be fine.

It would have been much worse if the "Hello World!" example used a Windows specific dialog box mechanism. (Don't read this).

B
Thanks. I just wish I understood the concept a bit more, like I said my textbook isnt quite a textbook, it seems its just lecture notes so it doesnt really give any context.
 

KnightWRX

macrumors Pentium
Jan 28, 2009
15,046
4
Quebec, Canada
Yes I am! I actually got something correct tonight. Lol my "homework" per se was to run a code given to us by my prof (shown below) in the compiler to make sure we can do it. so once i get this downloaded (unfortunately will take forever since I am on residence wireless) -- what should my next step be? if anyone is willing to explain that is :)

Code:
#include <iostream>

int main( )
{
   std::cout << "Hello world!\n";
   return 0;
}
Just copy/paste it in your favorite editor and save it with a .cpp extension. Then, it's just a matter of compiling/linking it with the GCC you installed. For C++, you'll want to use the g++ executable as so for a simple compile/link operation. This is all done under Terminal (Applications -> Utilities -> Terminal) :

Code:
$ pwd
/Users/username
$ cd dir_where_file_is_stored
$ g++ -Wall -o test test.cpp
$
If the command just returns to the prompt like my example did, then it's because it compiled fine. You should have an executable named test (the -o parameter specifies the executable name to create). You can run it as so :

Code:
$ ./test
Hello world!
$
You might want to learn a thing or two about Makefiles and GNU make for more complicated projects. If your code is strewn about multiple files, you have to first compile each into object code one by one (one file at a time) and then link them together manually. Makefiles and GNU make automate this process.

EDIT : Or just get Xcode which should hide a lot of this complexity.
 

balamw

Moderator
Staff member
Aug 16, 2005
19,368
974
New England
You might want to learn a thing or two about Makefiles and GNU make for more complicated projects.
Even for simple projects!

I've started using
Code:
make test
instead of your g++ command above from an earlier version of this thread. :p


----------

EDIT : Or just get Xcode which should hide a lot of this complexity.
But adds more things to learn (a different kind of complexity) if you aren't already familiar with an IDE.

B
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
I'm not even sure I'll know how to run this once it's installed. I'm really lost lol. Like I said I'm completely new to mac and between xmas and now have not had a lot of time to figure things out.

also is terminal equivalent to command prompt? im assuming
 

VPrime

macrumors 68000
Dec 19, 2008
1,721
82
London Ontario
To those saying don't use xcode do it all through terminal.. I disagree.
Sure that makes sense as a step for someone trying to get into computer science, or programming as a future career.
But if all you're trying to do is pass a class then I wouldn't bother with the terminal.
In xcode it is as simple as starting a new project (first prompt when it starts up).
Tell it you want to make a mac OSX command line application (in this case)
Then paste the code from your book into the text window. And click the button with a "play" icon on it (build and run).
Your results will be at the bottom in the console window.

Will take you all of 5 minutes to get going. This way you won't fall behind with your class.
Here is a video for Xcode 3.. The interface is slightly different, but you should be able to follow along.
http://www.youtube.com/watch?v=ZU_MT9PwKkk

edit:
Xcode 4 video..
http://www.youtube.com/watch?v=SGwS9XNal4I
 
Last edited:

mobilehaathi

macrumors G3
Aug 19, 2008
9,351
6,219
The Anthropocene
To those saying don't use xcode do it all through terminal.. I disagree.
Sure that makes sense as a step for someone trying to get into computer science, or programming as a future career.
But if all you're trying to do is pass a class then I wouldn't bother with the terminal.
In xcode it is as simple as starting a new project (first prompt when it starts up).
Tell it you want to make a mac OSX command line application (in this case)
Then paste the code from your book into the text window. And click the button with a "play" icon on it (build and run).
Your results will be at the bottom in the console window.

Will take you all of 5 minutes to get going. This way you won't fall behind with your class.
Here is a video for Xcode 3.. The interface is slightly different, but you should be able to follow along.
http://www.youtube.com/watch?v=ZU_MT9PwKkk

edit:
Xcode 4 video..
http://www.youtube.com/watch?v=SGwS9XNal4I
I find that an IDE only complicates things and hides important steps that a newbie really should know. Sure it streamlines a lot for the intermediate and advanced user, but I still think a beginner should start on the command line. Just MHO...
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
okay ummmm so ive downloaded that file from the link I was given up above.. but i installed it and now I have no idea where it went or whatever. how would i uninstall this? my god im in over my head
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
i just have no idea what to do now! how would i go about uninstalling this when i am done with it? and more importantly how do i USE it? :confused::confused::confused::confused:
 

lloyddean

macrumors 65816
May 10, 2009
1,002
16
Des Moines, WA
Everyone seems to have dropped out for dinner so I guest I'll give it a go.

Assuming you run the Xcode installer ...

Locate and run the "TextEdit.app" in the "Applications" folder.

Paste your code from above into the blank window and save it to whatever folder you plan to keep your Math programming projects with a name that ends with .cpp. Something along the lines of "MathAssignment1.cpp"

Now run (launch) "Terminal.app" located in Applications/Utilities.

The Terminal is analogous to the Windows command-line. You'll now need to tell the command-line where your "MathAssignment1.cpp" is with the 'cd' (change directory) command.

If you saved the "MathAssignment1.cpp" to your "Desktop" that would be -

cd ~/Desktop

Now type -

clang++ -Wall -o MathAssignment1 MathAssignment1.cpp

Assuming no errors you can run the executable with -

./MathAssignment1

Have fun!
 
Last edited:

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
bash: cd~/Desktop: No such file or directory

I did save it to my desktop, and thats what it said?
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
yep i did

----------

so i think i got it? I hit enter after i typed that last line in and a new file showed up on my desktop. is that all?