![](/style/images/good.png)
![](/style/images/bad.png)
How to use gcc instead of clang on macOS, specially M1? (Help)
source link: https://codeforces.com/blog/entry/88063
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
I code in C++, I was a Windows user, recently switched to mac. I downloaded gcc-10 from homebrew but still, whenever I compile on any editor, it got compiled with Clang. Then I deleted Clang by going to the directory where it was stored, I thought it will then compile with GCC. But now it stops compiling and throwing error messages.
Q.Why do I wish to use gcc instead of clang? -> Clang doesn't have <bits/stdc++.h> header and while solving one question I got to know it doesn't have unordered map also (read on StackOverflow later). -> And I don't know what more is not there in clang.
Can anyone please tell me ========================= either how to successfully compile C++ using gcc on MAC or can tell me all the difference between clang and gcc and how should I manage.
Even I talked with apple care for about 45 mins and they also don't know the solution.
I'm not sure about the case for M1. But if you type |
-
Actually, this doesn't work for me but after experimenting lot of stuff, I got the solution and a better understanding. I will share that in a different blog.
Thanks, for your reply:)
I'm not sure about M1 too, but in MacOS with Intel processors you can install gcc with |
-
You are correct only. For M1,
gcc-10
is located at/opt/homebrew/bin/gcc-10
.Actually, there are many blogs and tutorials for Intel chips, and nothing available exactly for M1. I will upload one :)
If you have another version of GCC, you should put it instead of 11th. I've tested it in an intel MacBookPro; it should work in M1 too. |
-
Just one correction, use this in the 3rd step
/opt/homebrew/bin/gcc-10
, instead of/usr/local/bin/g++
.-
No. You didn't get it.
/usr/local/bin/g++
is the path where I want to putg++
. By other side,$(which g++-11)
would be that path you mentioned.-
Actually, in M1 you need to make a different path, named
/opt/homebrew/bin/gcc-10
.Remaining is same as you said.
-
Well, if you do exactly what I said, and then make sure you have
/usr/local/bin/
in thePATH
variable of your shell, then you should not worry about that different path you're saying.Just to make it clear:
sudo ln -s pathSource pathDestination
creates a symbolic link frompathSource
topathDestination
.$(which g++-10)
returns the path for the commandg++-10
, that in your case is/opt/homebrew/bin/g++-10
. So, the command I typed would be equivalent tosudo ln -s /opt/homebrew/bin/g++-10 /usr/local/bin/
, and that's perfectly fine because AFAIR/usr/local/bin/
is part of thePATH
variable by default.
-
-
-
23 months ago, # | First, you need to install HomeBrew from https://brew.sh/ Then, run After installation completed, type Finally, to use
Now everything is OK. |
22 months ago, # | I use the M1 version of CLion. The steps to install gcc via homebrew are pretty much the same as they always were. To use gcc instead of clang within CLion, you can go to CLion -> Preferences -> Build, Execution, Deployment -> Toolchains -> C++ Compiler, and select the gcc compiler you downloaded. |
19 months ago, # | |
-
Thanks bro. Your solution worked for my m1.
-
Brother, how did you perform the 3rd step. — "added alias g++="g++ --std=gnu++17" to .zshrc file"
-
11 months ago, # | When compiling i simply give it a command of gcc-11, instead of just gcc.. This way it executes with the homebrew gcc verison |
8 months ago, # | Dear maverick_GOD and everone else who are using MAC, today I am gonna tell you the complete solution on how to use gcc compiler instead of using apple CLANG.
I will be pleased if this comment is helpful to anyone. Please share this commment so if anybody is trying to install gcc can see this solution. Thank you. Have a nice day:) |
-
Thanks a lot bro :) Was very helpful. I was stuck with clang for months and could not use gcc. Also sometimes we've tried too many times , so in /opt/homebrew/bin, on doing ln -s g++-12 g++, we get output as ln: g++ already exists. So first I needed to remove already existing g++ file.
for that on terminal, first i typed cd /opt/homebrew/bin , pressinng enter then i removed existing file by typing sudo rm g++ , pressed enter then I followed your steps from no. 12 from typing ln -s g++-12 g++ then enter And it worked ...
Thanks again
7 months ago, # | If your only concern is the header, get it from github and precompile it...afterwards it won't make a big difference if you use clang or gcc. |
|
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK