Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Compile C++ with xcode

Compile C++ with xcode
Thread Tools
Forum Regular
Join Date: May 2005
Location: Southaven, MS
Status: Offline
Reply With Quote
Oct 24, 2005, 09:26 AM
 
This is my first attempt at any code. I've got a C++ tutorial with lots of sample code to refer to. It tells you to compile some of the code to test your compiler. I installed a default installation of xcode 2.0. When I have a .cpp file open in xcode it won't allow me to compile. Everything under Build is greyed out as is all but three under Debug. Any suggestions on how I should do this?
Here's the code I used:
Code:
// Chapter 1 - Program 1 - CONCOM.CPP #include <iostream.h> /* This is the stream definition file */ void print_it(const int data_value); int main() { const int START = 3; // The value of START cannot be changed const int STOP = 9; // The value of STOP cannot be changed volatile int CENTER = 6; /* The value of CENTER may be changed by something external to this program. */ int index; /* A normal C variable */ for (index = START ; index < STOP ; index++) print_it(index); return 0; } /* End of program */ void print_it(const int data_value) { cout << "The value of the index is " << data_value << "\n"; } // Result of execution // // The value of the index is 3 // The value of the index is 4 // The value of the index is 5 // The value of the index is 6 // The value of the index is 7 // The value of the index is 8
iMac 17" 2GHz Core2Duo | 1GB RAM | 160GB hdd | Superdrive | Tiger and XP Pro
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Oct 24, 2005, 10:56 AM
 
Xcode can only build projects, not individual files. You can make a project with just that file in it, or you can use the C++ command line tool (c++ myfile.cpp).
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Mac Elite
Join Date: Jul 2002
Status: Offline
Reply With Quote
Oct 24, 2005, 12:14 PM
 
Make a new C++ tool project and replace the contents of the main.cpp file with what you posted and it should compile.
     
Forum Regular
Join Date: May 2005
Location: Southaven, MS
Status: Offline
Reply With Quote
Oct 24, 2005, 01:08 PM
 
Thanks, it worked.
iMac 17" 2GHz Core2Duo | 1GB RAM | 160GB hdd | Superdrive | Tiger and XP Pro
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:40 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2