<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Jan 11, 2014 at 12:56 AM, Shiyuan <span dir="ltr">&lt;<a href="mailto:gshy2014@gmail.com" target="_blank">gshy2014@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">There is another problem regarding to the coexistence of xcode gcc and gcc48 from macports. <div>When I do  &quot;port select gcc mp-gcc48&quot; , I can compile using &quot;g++&quot;. But when I switch back by &quot;port select gcc none&quot;, </div>

<div>I got the error: </div><div>







<p>&gt; g++ -g -o HelloWorld HelloWorld.cpp</p>
<p>-bash: /opt/local/bin/g++: No such file or directory</p><p>But strangely, when I do &quot;which g++&quot;,  I get &quot;/usr/bin/g++&quot;. Then why &quot;g++&quot; still try to involve &quot;/opt/local/bin/g++&quot; but not &quot;/usr/bin/g++&quot;? </p>
</div></div></blockquote><div> </div><div>`which` is often not a shell builtin and/or not using what your current shell&#39;s state is, and will often show you not what your current shell sees but what a new shell would see (or, in older versions especially with *csh, what you would see if you logged out and back in). You should not rely on it. `type` shows you (and is required by POSIX to show you) what the current shell &quot;knows&quot;, not what it would find if it were restarted.</div>
<div><br></div><div>In this case, the problem is that bash remembers where it found a command, rather than looking again for it every single time; you need to use `hash -r` to make it forget that it once saw /opt/local/bin/g++ so it will go find out that /usr/bin/g++ is currently the only one on $PATH. (Actually setting $PATH will do this automatically; removing an executable found somewhere on $PATH originally does not.)</div>
<div><br></div></div>-- <br><div dir="ltr"><div>brandon s allbery kf8nh                               sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>                                  <a href="mailto:ballbery@sinenomine.net" target="_blank">ballbery@sinenomine.net</a></div>
<div>unix, openafs, kerberos, infrastructure, xmonad        <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div>
</div></div>