image
image

Go Back   macosx.com > Design, Media, Programming & Scripting > Software Programming & Web Scripting

Reply
 
LinkBack Thread Tools
  #1  
Old May 4th, 2005, 12:03 AM
Registered User
 
Join Date: May 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
bullfrog-xv is on a distinguished road
C++ compiling

I hav Xcode and i compile my program using project builder. This works (I think) but then i cannot run it, how do i run the program I just created. If no one can help me then can someone tell me how to compile and run a program using a simple text edit.
Thanks
Reply With Quote
  #2  
Old May 4th, 2005, 02:56 AM
texanpenguin's Avatar
Registered Penguin
 
Join Date: Feb 2003
Location: Australia
Posts: 881
Thanks: 0
Thanked 0 Times in 0 Posts
texanpenguin is on a distinguished road
You need to make sure you have a Target set up.

The easiest way to do simple text compiling is still the Terminal and a plain-text editor (like SubEthaEdit, BB Edit, or even the venerable TextEdit in Plain Text Mode).
Just save the file somewhere and type
g++ *filename*
into the Terminal (you'll want to cd to the path of the file first though).

In XCode, look at Targets.
__________________
15" MacBook Pro
Mac OS X v10.5.1
2.33GHz, 2GB RAM, 120GB HDD

5G iPod 60GB
Reply With Quote
  #3  
Old May 4th, 2005, 03:12 AM
Registered User
 
Join Date: May 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
bullfrog-xv is on a distinguished road
Quote:
Originally Posted by texanpenguin
(you'll want to cd to the path of the file first though).
I don't quiet understand "cd to the path" can you explain what you mean? And what does "cd" mean?
Thanks
Reply With Quote
  #4  
Old May 4th, 2005, 11:59 AM
cfleck's Avatar
tired
 
Join Date: Nov 2002
Location: Indianapolis
Posts: 825
Thanks: 0
Thanked 0 Times in 0 Posts
cfleck will become famous soon enough
cd means change directory. You execute it from the command line (via Terminal.app or xterm). You should probably look at some command line tutorials online just for good measure. They will help immensely.

http://www.osxfaq.com/Tutorials/LearningCenter/
http://www.macobserver.com/tips/macosxcl101/
Reply With Quote
  #5  
Old May 4th, 2005, 03:37 PM
Who, me?
 
Join Date: Feb 2005
Location: Near to Philly.
Posts: 382
Thanks: 0
Thanked 0 Times in 0 Posts
chornbe is on a distinguished road
I don't mean to sound like a jerk, honest, but does no one read basic manuals any more.

If you're looking to work in a terminal window you're only hurting yourself if you don't spend a few minutes learning the basics of navigating unix/linux. Get yourself a "using linux" or "using unix" book and spend some time getting familiar with the basics.

believe me, it'll save your butt to know how to get around and how to ensure you're not breaking something.

$.02
Reply With Quote
  #6  
Old May 4th, 2005, 05:45 PM
texanpenguin's Avatar
Registered Penguin
 
Join Date: Feb 2003
Location: Australia
Posts: 881
Thanks: 0
Thanked 0 Times in 0 Posts
texanpenguin is on a distinguished road
Alright, I'll explain in a little more detail how to do exactly what you'll need to do:

First, create a folder somewhere that you'd like to use as your code folder. It's probably going to be in your ~/Documents folder or in /Developer.

Once that folder has been created, copy this C++ program and save it as "HelloWorld.cpp" into that folder:

Code:
#import <iostream>
using namespace std;

int main()
{
cout << "Hello World!" << endl;

return 0;
}

Then, open the Terminal (you can find it in the Utilities folder in the Applications folder). In it, type cd *space*, but don't press return. Now go over to the window showing you the folder you created, showing the files it contains, and drag the tiny folder icon from the title bar (at the very top of the window) into the Terminal. Terminal will dump a path to that folder in. Now, in the Terminal, press return. What you've just done is to change the directory from your home folder (selected by default) to the folder which you create your code in.

You can type pwd and press return to print the path of the directory you're in (print working directory) to make sure you're in the right place.

Now type ls (that's a lowercase 'LS') and press return. That'll output all the visible files in that folder.

Now to compile your C++ program, just type:

g++ HelloWorld.cpp

That'll run HelloWorld.cpp through the GCC 3.3 Compiler (in Panther) or the GCC 4.0 Compiler (in Tiger).

To see your compiled program at work, type
Code:
./a.out
and press enter.

You should see "Hello World!" outputted.
__________________
15" MacBook Pro
Mac OS X v10.5.1
2.33GHz, 2GB RAM, 120GB HDD

5G iPod 60GB
Reply With Quote
  #7  
Old May 6th, 2005, 11:03 PM
Who, me?
 
Join Date: Feb 2005
Location: Near to Philly.
Posts: 382
Thanks: 0
Thanked 0 Times in 0 Posts
chornbe is on a distinguished road
You, sir, are one patient man
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting 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 Off
Pingbacks are Off
Refbacks are Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
glib errors when compiling libIDL-0.6.8 kilowatt Software Programming & Web Scripting 3 January 10th, 2005 05:34 PM
compiling mesa libs on 10.2 resglowing Unix & X11 0 December 3rd, 2002 02:11 PM
FINK vs. compiling from scratch ksignorini Unix & X11 4 July 28th, 2002 12:14 PM
Problems compiling PHP Fahrvergnuugen Mac OS X System & Mac Software 1 December 8th, 2001 10:48 PM
GL libraries...for commandline compiling jmmistrot Software Programming & Web Scripting 0 October 11th, 2001 07:28 PM


All times are GMT -5. The time now is 10:04 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC1
Copyright 2000-2010 DigitalCrowd, Inc.