Forums | MacLife
You are not logged in.
#1 2003-01-15 4:56 pm
How do I create UNIX apps in OS X
Hello and thank you for viewing my post!
I am currently taking a course in C++ and the professor wants all projects to be compiled using g++. I am wondering if I can write my code, compile it, and build it to test it out in the OS X terminal and then just ftp it over to the professor instead of working in the university's computer lab till 3:00 a.m. (I am not a very good programmer so it takes me a while to get my programs up an running
). Things I would like to know are:
Would I use a text editor, compile the file, and build the file all in Terminal or can I use the Developer's Tools instead? (I heard that I could, but I am uncertain how
)
Do I have g++ on my machine already? (I have 10.2.3 with the Developer's Tools installed)
Do I need fink? (I have downloaded it but have not looked at the documentation to determine if I will use it)
Is there anything else I should know? (since I really don't have a clue
)
~jlk
I've got a LANDSAT image of my house! Check it out!
Offline
#2 2003-01-15 6:16 pm
Re: How do I create UNIX apps in OS X
Hey, I'm also taking my first C++ class in college. Yes, g++ is installed, in the terminal type:
g++ file.cpp (sometimes .cc)
This compiles it and creates a file called a.out, to run it, type in (while in the same directory):
./a.out
I'm pretty sure fink isn't installed, but pico and vi are (my class uses vi).
Also open ProjectBuilder (in Developer folder) and you can create C++ apps, debug and run them all together.
-bonk
PB 17" :: 1.33gHz :: 1gb :: 80gb @ 5400rpm
Dual 500mHz :: 576mb :: 180gb (120+40+20)
Offline
#3 2003-01-15 10:31 pm
- Odin
- Member

- Registered: 2000-07-16
- Posts: 5706
Re: How do I create UNIX apps in OS X
sounds like he already answered all your questions..
Devtools installs gcc and I believe several more text editors.. I don't remember if emacs or vi were installed by default in OS X, I think they came with the dev tools.
It really is that simple.. Just make the .cpp in the text editor of your choice, and compile using the command 'g++ filename.cpp'.
You don't need fink unless you want to install more, different, *nix software.
Offline
#4 2003-01-16 12:55 pm
Re: How do I create UNIX apps in OS X
Thanks for the info. I am greatly appreciative.
One more question: Since all my projects will involve classes in multiple files (.h and .cpp), do I need to create a makefile to tie the files together or can g++ do this for me?
~jlk
I've got a LANDSAT image of my house! Check it out!
Offline
#5 2003-01-16 1:18 pm
- Jehannum
- Banned
- From: Albuquerque
- Registered: 1999-07-24
- Posts: 8404
Re: How do I create UNIX apps in OS X
REMEMBER: test on your university computer before turnin. I ran across a highly annoying bug in my last program which turned out to be a default setting in gcc 2.95 (on the CS machines) and gcc 3.2 (on my iBook) - inheritance is by default private (snuh?!) in 2.95, but is by default public in 3.2. There are other annoying little bugs like that that you'll run up against when it comes down to the wire.
and you can make makefiles easily, since make is installed by default on your OS X box.
"Goodness he just keeps going and going. He's like the energizer bunny of stupid." - Neut
Your powers are useless! I'm wearing my tin-foil underwear!
Offline
#6 2003-01-16 1:53 pm
Re: How do I create UNIX apps in OS X
Hey Jehannum,
Thanks for the warning and the info on the makefiles. I just read that you can switch to the 2.95 compiler by typing the command 'sudo gcc_select 2'. This changes the default compiler to gcc 2.95.2. If you want to go back to the original compiler, just change the 2 to a 3 in the previous command. This info came from PortingUNIXToOSX.pdf off of the Apple Developer site here.
I've got a LANDSAT image of my house! Check it out!
Offline
#7 2003-01-16 4:54 pm
- Jehannum
- Banned
- From: Albuquerque
- Registered: 1999-07-24
- Posts: 8404
Re: How do I create UNIX apps in OS X
Hey Jehannum,
Thanks for the warning and the info on the makefiles. I just read that you can switch to the 2.95 compiler by typing the command 'sudo gcc_select 2'. This changes the default compiler to gcc 2.95.2. If you want to go back to the original compiler, just change the 2 to a 3 in the previous command. This info came from PortingUNIXToOSX.pdf off of the Apple Developer site here.
But 3.2 is so much faster and nicer than 2.95! Namespaces and inheritance work the right way. So, I develop on 3.2 and, in general, I get the same results under 2.95, since 3.2 is by far more strict on c syntax.
"Goodness he just keeps going and going. He's like the energizer bunny of stupid." - Neut
Your powers are useless! I'm wearing my tin-foil underwear!
Offline
#8 2003-01-17 3:02 pm
Re: How do I create UNIX apps in OS X
I just found out that the version of gcc the school is using is 2.95 so until I am finished with this course I will have to use the 2.95 version. However, Jehannum, thank you for informing me about the improved useage of namespaces and inheritance with gcc 3.2. I will certainly switch back afterwards.
~jlk
I've got a LANDSAT image of my house! Check it out!
Offline

