|
#1
| |||
| |||
| 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 |
|
#2
| ||||
| ||||
|
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 |
|
#3
| |||
| |||
| Quote:
Thanks |
|
#4
| ||||
| ||||
|
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/ |
|
#5
| |||
| |||
|
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
__________________ ---------------------------- chris@chornbe.com http://learntomac.blogspot.com/ http://motorcyclemanifesto.blogspot.com/ |
|
#6
| ||||
| ||||
|
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 You should see "Hello World!" outputted.
__________________ 15" MacBook Pro Mac OS X v10.5.1 2.33GHz, 2GB RAM, 120GB HDD 5G iPod 60GB |
|
#7
| |||
| |||
|
You, sir, are one patient man
__________________ ---------------------------- chris@chornbe.com http://learntomac.blogspot.com/ http://motorcyclemanifesto.blogspot.com/ |
![]() |
| Bookmarks |
| Thread Tools | |
|
|
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 |