-bash g++:command not found

Joined
Apr 20, 2012
Messages
3
Reaction score
0
Points
1
"Newbie" question:
I'm learning some C++ at university, so I installed Xcode on my mac in order to compile and run my small programs.
There is absolutely no issue as long as I work within Xcode projects, that is to say writing and running "within Xcode".
Instead, I can't manage to compile (and run) them directly from the terminal window because, if I type "g++ file_name.cpp", I get the answer "-bash g++ command not found"; the same happens with gcc.
I thought that installing Xcode would provide me automatically with a proper compiler.

Can you help me?
PS: there are some similar threads but I couldn't find another user with exactly my same problem...
 

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)
If you're using a newer version of Xcode, you need to install the command line tools manually. In Xcode, go to Preferences > Downloads and install the "Command Line Tools" package.
 
OP
B
Joined
Apr 20, 2012
Messages
3
Reaction score
0
Points
1
Thank you for the prompt answer.
I'm trying right now!

edit:
it worked! thank you very much

now I just have to do some practice...
 
OP
B
Joined
Apr 20, 2012
Messages
3
Reaction score
0
Points
1
Alias

Ok, now that I have a working g++, I would like to make a shortcut that compiles the .gpp file, renaming the o.out file in a given way; the problem is: I can't figure out the syntax.

what I write: g++ my_file.cpp -o my_file
what I'd like to write: --alias-- my_file.cpp

thanks in advance
 
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.
a quick bash script like this would work.


Code:
#!/bin/bash
in1=$1
in2=`echo $in1|tr -d '.cpp'`
g++ $in1 -o $in2
 

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