問題描述
這已經困擾我一段時間了.我正在嘗試編譯一個巨大的 C++ 文件(我知道它可以正常工作,因為它在我的 Arch Linux 計算機上運行良好).當我在我的 mac 上檢查我的 GCC 版本時,它返回以下內容
This has been plaguing me for awhile now. I am trying to compile a huge C++ file (I know it works as I it works fine on my Arch Linux computer at work). When I checked my GCC version on my mac It returns the following
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
我還使用 Homebrew 安裝了最新的 GCC 版本
I have also installed the most recent GCC version using Homebrew with
brew install gcc49
我現在的問題是如何將新安裝的 GCC 版本應用為終端使用的默認版本?
My question now is how do I apply that newly installed GCC version to be the default version that the terminal uses?
我也知道,當您使用自制軟件來安裝 gcc 時,它會將其命名為 gcc-49,這樣包之間就不會混淆.
I am also aware that when you use homebrew to isntall gcc it names it gcc-49 so that there is no confusion between packages.
我不知道如何用我安裝的 4.9 版本替換 XCode 附帶的 4.2.1 版本.
I have no idea how to replace the 4.2.1 version that comes with XCode with the 4.9 version I have installed.
謝謝
切換到我的mac獲取gcc的完整返回語句 --version
Switched to my mac to get the full return statement of gcc --version
我在這里的最終目標是能夠導航到目錄并能夠輸入
Edit 2: My end game here is to be able to navigate to the directory and be able to type
make
sudo make install
安裝已經制作好的守護進程.現在,隨機包和標準庫會返回大量錯誤
to install the daemon that has been made. Right now that returns tons of errors with random packages and the Standard Library
推薦答案
默認情況下,homebrew
將它安裝的包的可執行文件(二進制文件)放置到 /usr/local/bin
- 當您考慮它時,對于本地用戶安裝的二進制文件來說,這是一個非常明智的地方 - 與包含屬于核心操作系統的標準二進制文件的 /bin
相比.因此,您的 brew
命令應該已將 gcc-4.9
安裝到 /usr/local/bin
中.現在的問題是如何使用它……您有多種選擇.
By default, homebrew
places the executables (binaries) for the packages it installs into /usr/local/bin
- which is a pretty sensible place for binaries installed by local users when you think about it - compared to /bin
which houses standardisded binaries belonging to the core OS. So, your brew
command should have installed gcc-4.9
into /usr/local/bin
. The question is now how to use it... you have several options.
選項 1
如果你今天和明天只想編譯一兩件事,然后可能不會再使用編譯器,你不妨調用homebrew
gcc> 完整路徑如下:
If you just want to compile one or two things today and tomorrow, and then probably not use the compiler again, you may as well just invoke the gcc
installed by homebrew
with the full path like this:
/usr/local/bin/gcc-4.9 --version
選項 2
如果您打算大量使用 gcc
,每次都明確輸入完整路徑會有點煩人,因此您可以將以下內容放入您的 ~/.bash_profile
If you are going to be using gcc
quite a lot, it gets a bit tiresome explicitly typing the full path every time, so you could put the following into your ~/.bash_profile
export PATH=/usr/local/bin:$PATH
然后啟動一個新終端,它會知道它需要查看/usr/local/bin
,因此您只需輸入
and then start a new Terminal and it will know it needs to look in /usr/local/bin
, so you will be able to get away with simply typing
gcc-4.9 --version
選項 3
如果你只想使用gcc
來調用編譯器,而不用擔心實際版本,你可以做上面的選項2,另外創建一個像這樣的符號鏈接
If you just want to use gcc
to invoke the compiler, without worrying about the actual version, you can do Option 2 above and additionally create a symbolic link like this
cd /usr/local/bin
ln -s gcc-4.9 gcc
這將允許您通過在命令行輸入 gcc
來運行 homebrew
安裝的 gcc
,就像這樣
That will allow you to run the homebrew
-installed gcc
by simply typing gcc
at the command line, like this
gcc --version
注意:
如果你以后想安裝,比如 gcc-4.13
或類似的,你可以像以前一樣執行 brew install
,然后像這樣更改符號鏈接:>
If you later want to install, say gcc-4.13
or somesuch, you would do your brew install
as before, then change the symbolic link like this:
cd /usr/local/bin
rm gcc # remove old link from gcc to gcc-4.9
ln -s gcc-4.13 gcc # make new link from gcc to gcc-4.13
請注意,如果您實際使用的是 C++
而不是 C
,則需要針對 g++
修改上述內容以代替 gcc
.
Note that if you are actually using C++
rather than C
, you will need to adapt the above for g++
in place of gcc
.
這篇關于OSX - 用通過 Homebrew 安裝的 4.9 替換 gcc 版本 4.2.1的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!