image
image

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

Reply
 
LinkBack Thread Tools
  #1  
Old April 4th, 2001, 09:25 AM
Registered User
 
Join Date: Apr 2001
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
SpacemanSpiff2 is on a distinguished road
Question

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

Reply With Quote
  #2  
Old April 4th, 2001, 09:44 AM
Unperson Spotter
 
Join Date: Mar 2001
Posts: 275
Thanks: 0
Thanked 0 Times in 0 Posts
ladavacm is on a distinguished road
Compiling C++

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
Reply With Quote
  #3  
Old April 4th, 2001, 11:52 PM
Registered User
 
Join Date: Apr 2001
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
SpacemanSpiff2 is on a distinguished road
Thumbs up

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
Reply With Quote
  #4  
Old April 5th, 2001, 12:37 PM
Message Board God
 
Join Date: Sep 2000
Location: Iowa State University
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
mtc7501 is on a distinguished road
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.
__________________
PowerMac BW G4/500 (Rev 2 BW)
-256MB RAM
-ATI Rage 128
Powerbook G3/500
-256MB RAM
Powermac 7500/440g3
-64MB RAM
Reply With Quote
  #5  
Old May 4th, 2005, 02:33 AM
Registered User
 
Join Date: May 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
bullfrog-xv is on a distinguished road
When I try

When i try that it displays this message:

ld: can't locate file for: -lcrt1.o
Whats wrong
Reply With Quote
  #6  
Old May 4th, 2005, 10:56 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
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.
Reply With Quote
  #7  
Old May 6th, 2005, 08:49 PM
mkwan's Avatar
Tech
 
Join Date: Aug 2001
Location: Canada
Posts: 241
Thanks: 0
Thanked 0 Times in 0 Posts
mkwan is on a distinguished road
what's wrong with filenames ending in ".cpp"?
__________________
mkwan

UNIX was created in the late 1960s, in an effort to provide a multiuser, multitasking system for use by programmers. The philosophy behind the design of UNIX was to provide simple, yet powerful utilities that could be pieced together in a flexible manner to perform a wide variety of tasks.
Reply With Quote
  #8  
Old May 6th, 2005, 10:06 PM
lurk's Avatar
Mitä?
 
Join Date: Mar 2002
Location: Land o' skeeterz
Posts: 2,087
Thanks: 0
Thanked 0 Times in 0 Posts
lurk is on a distinguished road
Quote:
Originally Posted by mkwan
what's wrong with filenames ending in ".cpp"?
Nothing, it will work fine.
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Jaguar vs. Linux: Same code, different output!? cyberkazoo Software Programming & Web Scripting 1 February 25th, 2003 04:27 AM
compiling mesa libs on 10.2 resglowing Unix & X11 0 December 3rd, 2002 01:11 PM
Compiling Java Source Code RockyMorris Software Programming & Web Scripting 2 May 23rd, 2002 01:17 PM
newbie: compiling c code bluefossil Mac OS X System & Mac Software 6 February 3rd, 2002 03:09 PM
code for posting graphics to thread post or guestbooks? edX Design & Media 5 December 17th, 2001 01:59 AM


All times are GMT -5. The time now is 01:12 AM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.5.1
Copyright 2000-2010 DigitalCrowd, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52