# C++ on OSX for dummies



## themacko (Jan 13, 2002)

Sup guys, I have to take a C++ class this semester.  I know nothing about programming besides the fact that this class is focusing on Microsoft Visual C++.  With that said, can I write and compile (rather simple) C++ programs on my Mac that would work on my professor's PC?

I downloaded the Dev ToolKit off of the Apple site, but I haven't installed it yet and I'm not sure exactly what to do here.  Keep in mind, that if it's too much of a pain in the ass I can just use the computers in the lab, which I would probably have to do anyways to make sure it all works.

So anyways, thanks for any suggestions!


----------



## houchin (Jan 13, 2002)

It depends on the projects you have.

If your programming assignments focus on the creation of command line applications that don't have GUI's, and you're just using the standard C++ cross-platform stuff, then the only difference will be in the project file; the source code will in general be unchanged. You may run into a few gotchas, as the include files are a bit different and since Intel systems are little endian and Mac's are big endian, but I would think the problems you'd have in a programming class would be minor.

If, however, your assignments involve creating GUI applications with the Windows API's, then you will have to do the stuff on the computer lab's systems.

Even if you do find you can complete your assignments on your mac, I would
at a minimum go to the computer lab and verify that they compile and run in Visual C++ before you turn them in.


----------



## themacko (Jan 13, 2002)

Yeah .. I'll probably just stick to the computer lab then.  Oh well...  thanks!


----------



## Koelling (Jan 15, 2002)

I was going to start a new thread but this is exactly what I want to post in. I am also in a beggining programming class this semester which will cover C and C++. My teacher hardly knows anything about windows or macintosh, he just does unix so he is no help. What kind of compilers are there for simple stuff? In the lab yesterday we downloaded some kind of GNU compiler (this was in MS DOS) so the TA could tell us the basics on how to do stuff. We used emacs as the text editor and when it came time to compile we used this:

g++ heatwave.cxx -Wall -o heatwave
(this is after pushing ESC X compile and deleating 'make -k' to put this in)

I believe I am looking for a compiler to replace the g++ with because when I used Mac's emacs I got an error. I inserted c++ on a whim and it said compiling compleate but I can't open 'heatwave' from anything(it looks like a doc in the finder) under the DOS stuff we did in class it output heatwave as a .exe

Is there in fact a compiler in the system? I feel like I am in the dark about terminology but I could clarify what I am doing if anyone can help me. I have the same situation with Macko, I could buy codewarrior if that is what I need to do but all I need to turn in is the code so I basicly just need a compiler to test and such.


----------



## houchin (Jan 15, 2002)

It sounds like you already have the developer tools installed, but if not, get them (free) and install them.

Once you start working in the terminal, the only difference between the Mac and the Unix stuff at your school is that g++ is called c++ and gcc is called cc. make is there, and everything runs exactly how it should.

If you type the command "c++  heatwave.cxx -Wall -o heatwave" and
if heatwave.cxx compiles correctly, you should have a file called "heatwave"
in the same directory you're currently in. You must run that file from the command line, by typing "heatwave"

Given that you're working in a Unix environment at school, you should not have any issues other than g++ vs c++ for your applications, but I would still recommend that you make sure your stuff compiles and runs on the schools system before you submit your assignments.


----------



## blb (Jan 15, 2002)

Note, depending on your PATH you may have to run *./heatwave* after compiling as the current directory may not be in PATH.


----------



## Koelling (Jan 15, 2002)

Thanks, thats all I had to do. I am curious because of my newbie status to unix, what exactly ./ before heatwave does. I can see heatwave in the directory I'm working in but simply typing heatwave didn't work. Sorry to be so dumb about it but I would like to know.


----------



## houchin (Jan 15, 2002)

> _Originally posted by blb _
> *Note, depending on your PATH you may have to run ./heatwave after compiling as the current directory may not be in PATH. *



Argghhh. Forgot about that. The first thing I do on any unix system is go and put . first in my path. I really wish this was the default...

Since you're going to be doing software development, I suggest you add it. Just edit /usr/share/init/tcsh/path. I can't remember if I created this file or if it was there by default. If that file doesn't exist, just creat it with the following contents:

set path = (. $path)

If it's already there, add "." followed by a space, before the first entry in the list.

Then just close the terminal window and open a new window, and everything should work just fine


----------



## blb (Jan 15, 2002)

> _Originally posted by Koelling _
> *Thanks, thats all I had to do. I am curious because of my newbie status to unix, what exactly ./ before heatwave does. I can see heatwave in the directory I'm working in but simply typing heatwave didn't work. Sorry to be so dumb about it but I would like to know. *



All *./program* means is to run something called _program_ located in your current directory (which, in Unix, can be referred to simply as ".").  ".." is another standard directory, which refers to the directory up one from your current (ie, in /Users/username/Public, ".." would refer to /Users/username, hence the regular use of *cd ..* to move up one directory).


----------



## URIEL007 (May 25, 2006)

ok people, here is the dealio.

I've just started working with mac's in my workplace and I'm having some trouble making anything with C++.

I open the terminal and punch in: 

emacs hello.cpp

to create a new c++ program. 
it changes the terminal window into an emacs window and I write the hello world program. I select file>save and it tells me I have to save as a .term file.

when I do that, close the emacs window and reopen another terminal and go: ls
it shows me a file called #hello.cpp#

what's going on? how do I do this on macs?

any advice would be appriciated, thnx


----------



## ElDiabloConCaca (May 25, 2006)

Are you doing a "File > Save As" from the topmost menubar?  That menu is for saving terminal sessions.

You need to save the file from emacs itself, not the menubar.  The man page on emacs should tell you how to do this.


----------



## lurk (May 26, 2006)

C-x C-s  (That is control X then control S)


----------

