# Compiling C++ code



## SpacemanSpiff2 (Apr 4, 2001)

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


----------



## ladavacm (Apr 4, 2001)

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


----------



## SpacemanSpiff2 (Apr 4, 2001)

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


----------



## mtc7501 (Apr 5, 2001)

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.


----------



## bullfrog-xv (May 4, 2005)

When i try that it displays this message:

ld: can't locate file for: -lcrt1.o
Whats wrong


----------



## cfleck (May 4, 2005)

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.


----------



## mkwan (May 6, 2005)

what's wrong with filenames ending in ".cpp"?


----------



## lurk (May 6, 2005)

mkwan said:
			
		

> what's wrong with filenames ending in ".cpp"?



Nothing, it will work fine.


----------



## djnik_2 (Oct 13, 2009)

*how i could find dev c++ for mac????*


----------



## djnik_2 (Oct 13, 2009)

*how i could find dev c++ for mac???*


----------



## djnik_2 (Oct 13, 2009)

*how i could find dev c++ for mac or something that does the same with dev c++???
*
*
                           ! IMPORTANT I NEED IT FOR UNIVERSITY ! *


----------



## ElDiabloConCaca (Oct 13, 2009)

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.


----------



## djnik_2 (Oct 16, 2009)

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...


----------



## ElDiabloConCaca (Oct 16, 2009)

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.


----------



## djnik_2 (Oct 28, 2009)

hi ...
how i could find the drivers for my mac about my cell phone (omnia i900)?


----------



## ElDiabloConCaca (Oct 28, 2009)

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.


----------



## Satcomer (Oct 28, 2009)

djnik_2 said:


> hi ...
> how i could find the drivers for my mac about my cell phone (omnia i900)?



http://mac.eltima.com/sync-mac.html

Your welcome! Now go get some education and learn how to use Google.


----------



## djnik_2 (Oct 29, 2009)

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


----------



## djnik_2 (Oct 29, 2009)

a ok now i saw it


----------



## djnik_2 (Nov 2, 2009)

Hi..

How i could find the libraries ( *MinGW* and *Dev-Cpp* ) for my mac(i have installed  Xcode) ?


----------



## ElDiabloConCaca (Nov 2, 2009)

MinGW: http://crossgcc.rts-software.org/doku.php (binaries available for both PPC and Intel based Macs)

I couldn't find much on Dev-Cpp, but I believe if you dive into the MacPorts collection, you may find what you need there.


----------



## ex2bot (Nov 2, 2009)

Wow! Satcomer, El Diablo, you two do not get enough credit (referring, of course, to your answering five questions in this thread alone).

Bot


----------



## djnik_2 (Dec 6, 2009)

i have a portal hard disk for my mac and one for my pc....
when i connect the mac portal hard disk to pc it doesn't work and when i connect the pc portal hard disk to mac it doesn't work too... what i have to do that i could use both disks on both systems...


----------

