cant execute compiled file with g++

Joined
Jan 27, 2012
Messages
5
Reaction score
0
Points
1
Location
western colorado
Your Mac's Specs
imac osx 10.6.8
using osx 10.6, installed xcode 3.1.2 and successfully used.
Then used Terminal, compiled very small pgm - using one cout statement. Cannot execute or find compiled pgm even by using command g++ name.cpp -o outstuff.
Compile seems to have been successful but I cannot find in any folder the output. I think that auto linking would be done - ?? Several net people said after compile - just type ./a.out to run. No workee.
Thanks for any help - loux
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
After you compile an app, unless you've specified a binary name, you should have an "a.out" binary. What are the commands you're executing?
 
OP
L
Joined
Jan 27, 2012
Messages
5
Reaction score
0
Points
1
Location
western colorado
Your Mac's Specs
imac osx 10.6.8
terminal: /developer/usr/bin g++ xtest.cpp.save -o stuff
terminal: ./stuff
error mess from bash: no such file or directory
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
Is your binary there when you do an ls? Your syntax is correct.

Code:
Mikes-iMac:foo mike$ g++ main.cpp -o foobar
Mikes-iMac:foo mike$ ls
foo.1    foobar   main.cpp
Mikes-iMac:foo mike$ foobar
-bash: foobar: command not found
Mikes-iMac:foo mike$ ./foobar
Hello, World!
Mikes-iMac:foo mike$
 
OP
L
Joined
Jan 27, 2012
Messages
5
Reaction score
0
Points
1
Location
western colorado
Your Mac's Specs
imac osx 10.6.8
ls lists no file that I named in the g++ xtest.cpp.save -o stuff.
It does list the file xtest.cpp.save which I created with Pico.
stuff has disappeared and the xcode compiler just threw it away!
Loux
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
.. and you got no errors during compile, have full write permissions to the directory etc?
 
OP
L
Joined
Jan 27, 2012
Messages
5
Reaction score
0
Points
1
Location
western colorado
Your Mac's Specs
imac osx 10.6.8
no errors during compile. full r w permission to source code. I do not know how to give full r/w permission the usr directory but I assume I am the only user the only admin on this personal mac in my home. Fantastic communications, Mike. I never knew that the forum would help this much - only signed on today.
Loux in Colo.
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
Try adding a -v switch, and post the output. Also you can try doing it as..

g++ xtest.cpp.save -o ~/stuff

at which point it should be in your home directory
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
You don't need the /Developer/usr/bin/ bit - gcc should be in your path. ;)

The command you executed is no different than what Dysfunction or I execute which creates a binary in the current working directory. It's hard to tell you what might be wrong with this since there is absolutely nothing wrong with your command. My only suggestion would be to check what Dysfunction mentioned - privileges for the current working directory. Out of what directory are you trying to compile this code?
 
OP
L
Joined
Jan 27, 2012
Messages
5
Reaction score
0
Points
1
Location
western colorado
Your Mac's Specs
imac osx 10.6.8
I never succeeded in compiling with g++ in terminal. I do wish to correct myself: I had xcode3.2.1 and not 3.2.2. I uninstalled 3.2.1 and downloaded xcode 3.2.2 for Apple. This version has a very nice interface for beginners. Click in new project ( in the intro ), click on Application and command line and you have a nice setup for c prog - using the good editor and build and run. Now I see no reason to mess around with terminal and g++. Just thought people would like to know. Thanks for the help I did get - Loux
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top