Compiling C++ code

SpacemanSpiff2

Registered
I'm just starting to learn C++ and i need to know how to compile C++ programs in OS X. I've tried just typing: cc prog1.cpp in the terminal, but that doesn't work. I know it's not my code because it's straight out of my C++ book. Is there a way to do this in Project Builder? (yes i have the developer tools cd installed) Please be very specific...i'm new to UNIX and programming in general. Luckily the book i'm using seems pretty straightforward and so far just reading through it (can't compile...argh!!) i think i'm understanding most of it, so i'm really anxious to actually get something compiled to see if i'm actually understanding this stuff.

Spaceman Spiff

 
gcc ain't MS Visual C++

so the source names should end either with cc or C (even though it may know cpp).

However, to get correct runtime initialization, you have to compile with

c++ testfile.cc

which shoul result with a.out in the current directory. You can start it with

./a.out

Resulting file can be renamed automatically, using

c++ testfile.cc -o whatever

and started with

./whatever
 
Thanks alot! Now i can finally move past the first chapter without wondering if i'm really understanding or not. By the way i got the .cpp and cc testfile.cpp straight out of the book under the 'UNIX' instructions.
Spaceman Spiff
 
Project Builder is easy to use too. All you have to do is start a new project and when it asks for the type you select "C++ Tool". Then, you can just type all your stuff into the main.cpp and then click the build button. It will save the compiled program as the name of your project in your projects folder. You just drag that program to the terminal and run it. No problems at all.
 
Just a suggestion. If you are just learning to program and don't have much of a grasp of the command line tools, stay away from the IDEs like Project Builder/XCode. They will make it easier in some regards, but you will learn a lot more on the command line, at least while you are still getting started.
 
how i could find dev c++ for mac or something that does the same with dev c++???


! IMPORTANT I NEED IT FOR UNIVERSITY !
 
Install XCode. It includes all the command-line compilers and utilities you'll need for C++ (gcc, cc, etc.).

If you wish to develop in an IDE, then you can use XCode directly.

There is no need to post the exact, same request three times in a row. Once is plenty. If someone knows the answer, they'll be along to answer you whenever they get around to it -- this is a public forum staffed by volunteers just like yourself, so don't expect to get immediate answers. Answers may take a few minutes, a few hours, a few days, or sometimes you won't get an answer at all if no one knows what you're asking about.
 
ok sorry i was nervous because i have to do a lot of exercises... i download the Xcode and says that i must have the mac os x 10.6 where i could find it freeware/???

thank you and sorry again...
 
Log into your ADC account at connect.apple.com, click the "Downloads" link, click "Developer Tools" under "Downloads" on the right-hand side, then scroll down the page until you find XCode 3.1.4.

Download that.
 
That depends on what you want to do with your cell phone (tethering? Bluetooth sync? USB sync?) and whether or not there even is a driver available for that phone.
 
i would like to do everything that i used to do when i had a pc... transfer files sync phone and others...i will connect it with usb cable
 
Back
Top