0

I'm trying to compile a c++ program on the Mac terminal with gcc then the source files path. I've found some short term fixes on the Internet but I want it so it works every time. Also I hardly know anything about the Terminal so can the solution be explained very simply.

echo $PATH gives:

/Library/Frameworks/Python.framework/Versions/2.7/bin:’/usr/local/bin:??

/bin/cat ~/.profile prints no such file or directory,

/bin/cat ~/.bash_profile prints:

export PATH=’/usr/local/bin:?? 
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
 PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

When I use gcc to compile the program I get "-bash: gcc: command not found"

However if I run the commands

export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"

…the terminal works. I'd like to know how to make it work without running those commands.

6
  • On my machine running OS X 10.10.5, I find gcc at /usr/bin/gcc. I do not think you can execute gcc until you install Xcode. Your post does not actually ask a question. So what is the exact problem you want solved? Mar 18, 2016 at 23:06
  • @BenBeazley Please confirm the modifications made by patrix♦.
    – klanomath
    Mar 19, 2016 at 0:29
  • What exactly is the problem you are facing here? Which command are you trying to run in bash, which error message do you get?
    – nohillside
    Mar 19, 2016 at 12:06
  • Your first PATH variable is messing up your PATH. Assuming you need /usr/local/bin, just have PATH="/usr/local/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}" export PATH" in your .bash.profile and go from there.
    – mtklr
    Mar 19, 2016 at 13:43
  • The PATH variable is exported with export PATH, but this won't help you if the PATH definition is wrong to start with. It also won't help you if your issue is not PATH related. So please help us help you in describing the problem you are facing with compiling C++ code, which things you've tried already and where you are stuck now.
    – nohillside
    Mar 20, 2016 at 9:52

1 Answer 1

2

Modify the file .bash_profile with nano or another appropriate editor:

Replace:

export PATH=’/usr/local/bin:?? 
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH 

by:

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
export PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH

Explanation:

The first line of your current .bash_profile

export PATH=’/usr/local/bin:?? 

modifies the standard value of $PATH given by /etc/paths from

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin 

to ’/usr/local/bin:?? - which is no valid path.

The fourth and fifth line of your current .bash_profile modifies $PATH to

/Library/Frameworks/Python.framework/Versions/2.7/bin:’/usr/local/bin:??

Since ’/usr/local/bin:? is no valid path the finally effective PATH is

/Library/Frameworks/Python.framework/Versions/2.7/bin

which completely breaks your standard PATH. You can still execute all executables in the above directories but you can't omit the superior directories (e.g. to execute nano you have to enter /usr/bin/nano instead of nano).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .