These days I'm trying to compile the following c++ code:
#include<vector>
const int MAXN=1e5+5;
std::vector<int> factor[MAXN];
signed main() {return 0;}
This code works while I'm using g++ 11.3.0. However, if I use g++ 13.1.0 or 12.1.0, I'll receive a compile error:
/var/folders/v7/yk8tz4j54cl2lhp1f80nyz700000gn/T//cc2HpyzP.s:371:29: error: unexpected token in '.section' directive
.section .data.rel.ro.local
Reinstalling the compiler doesn't works. What should I do?
Note I use Apple M1 with MacOS 13.2.1 (22D68).
Have you tried updating your Xcode command line tools? It worked for me. This might help: updating command line tools
Unfortunately, it doesn't work.
Try compiling with -O2.
Even if this worked, it'd still be a bug, or it could be sneaking in hidden bugs. You don't always want to compile with -O2.
Yeah, it's certainly not a great fix, but it's the only one I've found so far. Before, I used to just decrease MAXN, but I've lost track of how many bugs I've gotten by forgetting to revert MAXN before submitting :/
For me, it doesn't work. :(
Same Error Here. It has to do with
MAXN
. If you set it small enough, it will work. Also, if you use the default Clang Apple provides, it works normally. See here for some discussion.I have also tried increasing the stack size, but it too doesn't work.
Is anybody here on Apple Silicon who uses gcc who fixed this problem? Thanks
Since decreasing MAXN has been suggested, try comparing the assembly for sufficiently small and too large MAXN. How do they differ?
I am using g++ 12.2.0 and it's working for me as for your concern you should run it on custom test if it's working then it may be an internal problem of your system.
Can i know how ur able to use g++ compiler with mac? Whenever i type g++ [filename] it always compiles with clang. How do I make it compile with g++?
In Mac, g++ is an alias for Clang. Use the g++ inside Homebrew folder, for me it is /opt/homebrew/bin/g++-13
See here
Ohh tysm. Ive been struggling with this for a while and just decided to deal with it and use clang lol. Appreciate it.
GCC has never officially supported macos, so you either revert to past versions or wait for proper fixes. One possible workaround is to use clang/llvm with libstdc++ instead of libc++.
For instance, if your gcc installation lies in
/opt/homebrew/Cellar/gcc/12.1.0
(which is the default path for aarch64 homebrew gcc), the compilation command would beDoes this provide access to gnu pbds? I have been trying to find a way to use pbds without gcc, because gcc does not support sanitizers on my computer
Yes, if libstdc++ in your system provides gnu pbds.
I'm trying your recommendation. Seems the most all around. But I'm facing strange errors in code execution:
A simple hello world program causes a segfault. And other codes not prints output when executed.
Compilation:
Any thoughts?
Same issue.
Same issue.
As Duds pointed out, this solution may cause mysterious segmentation fault. How to work out this problem?
P.S. When I tried to compile a single hello world, it looked normal.
But when I executed the program, the sanitizer gave me the following information:
GCC 11 works just fine for me, so you may want to install that particular version.
Not a permanent fix but using
-std=gnu++20
made the error go away for me (14/17 both have the bug it seems). The-O2
flag didn't work for me.Did you find any fix? Have you tried downgrading the compiler? I am also facing the same problem actually, so wanted to check if anyone had any progress with this
You can either downgrade the compiler to 11.x.x or use clang with libstdc++.
I am also facing the same problem.
if anyone still facing the same issue i fixed it by upgrading to gcc version 13.2.0 (Homebrew GCC 13.2.0)
write these steps in your terminal:
step 1:
brew update
step 2:
brew upgrade gcc
step 3:
g++ -v
it'll show apple clang version, in my case it was Apple clang version 15.0.0 (clang-1500.1.0.2.5)
step 4:
sudo rm g++
remove already existing g++ file by typing your sudo password
step 5:
ln -s g++-13 g++
step 6:
g++ -v
it'll switch to g++ version from apple clang version and in my case it shows gcc version 13.2.0 (Homebrew GCC 13.2.0)