New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Operating System General OS operation information and support

OS 10.5 - How To Compile .cpp Files On Mac


Post Reply New Thread Subscribe

 
Thread Tools
Sub-Zer0

 
Member Since: Jan 31, 2009
Posts: 49
Sub-Zer0 can only hope to improve

Sub-Zer0 is offline
I downloaded g++ and put

Code:
g++ password.cpp -o RandomPswrd
^ this in the termional but I get a bash error. The .cpp is in the gcc-4.40 folder. I just dragged the password.cpp into the folder. How can I compile these files?
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
do you get a specific bash error?

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
Sub-Zer0

 
Member Since: Jan 31, 2009
Posts: 49
Sub-Zer0 can only hope to improve

Sub-Zer0 is offline
-bash: g++: command not found

???

That's after I put in the code the RandomPswrd can be anything right?
QUOTE Thanks
Nethfel

 
Member Since: Feb 25, 2009
Posts: 2,109
Nethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of light
Mac Specs: Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10

Nethfel is offline
That error usually shows up if either:

1) The path to the executable is not in the exported path
2) The software hasn't been installed.

Just out of curiosity, have you installed g++, or the xcode developer pack? AFAIK, installing OSX by itself doesn't install the compilers. I think a version of XCode may be on the OSX disc that you can install, but you might as well get the most current version from apple and register as a developer. It's free and once properly installed, you should have no problems.

My Macs: Late 2013 rMBP w/ 750m; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Debian as a server; Apple TV (1080p version)
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,350
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is online now
GCC/G++ has to be compiled (the irony).

Download the developer tools from the Apple developer site or install Xcode/dev tools from your OS X installation disc to get an installed binary of GCC. Your best bet is to get it from the Apple dev site though as Xcode will be a newer version there.

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks
Sub-Zer0

 
Member Since: Jan 31, 2009
Posts: 49
Sub-Zer0 can only hope to improve

Sub-Zer0 is offline
bump

I downloaded xcode but now I get

i686-apple-darwin9-g++-4.0.1: password.cpp: No such file or directory
i686-apple-darwin9-g++-4.0.1: no input files
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
so is password.cpp in the directory you're running the compile from?

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
Sub-Zer0

 
Member Since: Jan 31, 2009
Posts: 49
Sub-Zer0 can only hope to improve

Sub-Zer0 is offline
What do you mean? It is in a gcc-4.40 folder.
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
you have to be in the directory your source is in to compile it.

So, for instance.. if your password.cpp was in your home directory under a folder called source.. you'd have to

cd ~/source
g++ password.cpp -o RandomPasswd

for it to compile. Or, you'd have to specify the path to the source like

g++ /path/to/password.cpp -o RandomPasswd

It can't guess where your source is.

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
Sub-Zer0

 
Member Since: Jan 31, 2009
Posts: 49
Sub-Zer0 can only hope to improve

Sub-Zer0 is offline
Ok, so I put a folder called source in finder > steven (right below "desktop") and inside the source folder is the password.cpp and now I get this:

password.cpp: In function ‘int main()’:
password.cpp:8: error: ‘srand’ was not declared in this scope
password.cpp:18: error: ‘rand’ was not declared in this scope
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
Now you have programatic errors

Try gdb password.cpp

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
Nethfel

 
Member Since: Feb 25, 2009
Posts: 2,109
Nethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of light
Mac Specs: Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10

Nethfel is offline
I'll give you a hint - you're missing an include file

My Macs: Late 2013 rMBP w/ 750m; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Debian as a server; Apple TV (1080p version)
QUOTE Thanks
Sub-Zer0

 
Member Since: Jan 31, 2009
Posts: 49
Sub-Zer0 can only hope to improve

Sub-Zer0 is offline
what include file?
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,350
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is online now
Read here and here - those may help.

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks

Post Reply New Thread Subscribe


« No Destination for Install of OS X | Change language »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Transferring files to mac, Where do you put them? MikeT Switcher Hangout 11 06-08-2007 04:02 AM
Can't copy files on to my mac accordingi2ime OS X - Operating System 0 01-02-2007 05:44 AM
Problems copying files... PC to Mac... ps zburd Running Windows (or anything else) on your Mac 0 10-10-2005 03:10 PM
Mac Users Get More ISP Choices schweb Apple Rumors and Reports 1 03-06-2003 11:57 AM

All times are GMT -4. The time now is 10:21 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?