2

I've recently upgraded my Mac to macOS Ventura, and upgraded my g++ to g++-12 using homebrew.

But later I found I will get the error: unexpected token in '.section' directive while compiling in a code like this:

#include<vector>
#include<iostream>
using namespace std;
const int N=1e5+10;
vector<int> test[N];

int main(){
    puts("Hello");
    return 0;
}

Which is usually OK to compile.

I'm Using Vscode with the coderunner Ad-on.

I tried to reinstall my compiler and recompile my compiler. I think it may help, but actually not.

I've searched the internet but I found nothing to solve the problem, either in Stackoverflow. It seems that everyone else having the same problem are not using C++.

I tried to ask my teacher and schoolmates, but no one knows why.

So why is this happening? Thanks in advance.

Here's the full log and verbose output

Using built-in specs.
COLLECT_GCC=g++-12
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/12.2.0/bin/../libexec/gcc/aarch64-apple-darwin22/12/lto-wrapper
Target: aarch64-apple-darwin22
Configured with: ../configure --prefix=/opt/homebrew/opt/gcc --libdir=/opt/homebrew/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-12 --with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr --with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl --with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 12.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=aarch64-apple-darwin22 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Homebrew GCC 12.2.0) 
COLLECT_GCC_OPTIONS='-v' '-std=c++14' '-Wall' '-o' 'test' '-mmacosx-version-min=13.0.0' '-asm_macosx_version_min=13.0' '-nodefaultexport' '-mlittle-endian' '-mabi=lp64'
 /opt/homebrew/Cellar/gcc/12.2.0/bin/../libexec/gcc/aarch64-apple-darwin22/12/cc1plus -quiet -v -iprefix /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/ -D__DYNAMIC__ test.cpp -fPIC -quiet -dumpbase test.cpp -dumpbase-ext .cpp -mmacosx-version-min=13.0.0 -mlittle-endian -mabi=lp64 -Wall -std=c++14 -version -o /var/folders/46/gnq0_xf15dj0d3drfw04nz7c0000gn/T//ccGl2TIh.s
GNU C++14 (Homebrew GCC 12.2.0) version 12.2.0 (aarch64-apple-darwin22)
        compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version 4.1.0-p13, MPC version 1.2.1, isl version isl-0.25-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/../../../../../../aarch64-apple-darwin22/include"
ignoring duplicate directory "/opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin22/12/../../../../../../include/c++/12"
ignoring duplicate directory "/opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin22/12/../../../../../../include/c++/12/aarch64-apple-darwin22"
ignoring duplicate directory "/opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin22/12/../../../../../../include/c++/12/backward"
ignoring duplicate directory "/opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin22/12/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/local/include"
ignoring duplicate directory "/opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin22/12/include-fixed"
ignoring nonexistent directory "/opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin22/12/../../../../../../aarch64-apple-darwin22/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/../../../../../../include/c++/12
 /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/../../../../../../include/c++/12/aarch64-apple-darwin22
 /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/../../../../../../include/c++/12/backward
 /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/include
 /opt/homebrew/Cellar/gcc/12.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/12/include-fixed
 /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks
End of search list.
GNU C++14 (Homebrew GCC 12.2.0) version 12.2.0 (aarch64-apple-darwin22)
        compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version 4.1.0-p13, MPC version 1.2.1, isl version isl-0.25-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 1e863952a13ea06101beaf74284a4c21
COLLECT_GCC_OPTIONS='-v' '-std=c++14' '-Wall' '-o' 'test' '-mmacosx-version-min=13.0.0'  '-nodefaultexport' '-mlittle-endian' '-mabi=lp64'
 as -arch arm64 -v -mmacosx-version-min=13.0 -o /var/folders/46/gnq0_xf15dj0d3drfw04nz7c0000gn/T//ccCP1tBg.o /var/folders/46/gnq0_xf15dj0d3drfw04nz7c0000gn/T//ccGl2TIh.s
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1as -triple arm64-apple-macosx13.0.0 -filetype obj -main-file-name ccGl2TIh.s -target-cpu apple-m1 -target-feature +v8.5a -target-feature +fp-armv8 -target-feature +neon -target-feature +crc -target-feature +crypto -target-feature +dotprod -target-feature +fp16fml -target-feature +ras -target-feature +lse -target-feature +rdm -target-feature +rcpc -target-feature +zcm -target-feature +zcz -target-feature +fullfp16 -target-feature +sm4 -target-feature +sha3 -target-feature +sha2 -target-feature +aes -fdebug-compilation-dir=/Users/rogerlu/Desktop/Code/20221118/source/卢盛西 -dwarf-debug-producer "Apple clang version 14.0.0 (clang-1400.0.29.202)" -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -mllvm -disable-aligned-alloc-awareness=1 -o /var/folders/46/gnq0_xf15dj0d3drfw04nz7c0000gn/T//ccCP1tBg.o /var/folders/46/gnq0_xf15dj0d3drfw04nz7c0000gn/T//ccGl2TIh.s
/var/folders/46/gnq0_xf15dj0d3drfw04nz7c0000gn/T//ccGl2TIh.s:477:29: error: unexpected token in '.section' directive
        .section .data.rel.ro.local
                                   ^
  • Are you sure you want a `100010` empty vectors? Or do you want a single vector with `100010` elements? – Some programmer dude Nov 18 '22 at 09:07
  • On a different note, your use of the *floating point* value `1e5+10`, mixing in the C function `puts` (for which you don't actually include the correct header file), possibly mixing array definitions and vector initialization, adding some extra elements to your array/vector, they all point to you learning programming from some kind of "competition" or "judge" site. Please note that such sites are *not* any kind of learning or teaching resources. They all assume that you already know programming and the selected language very well. – Some programmer dude Nov 18 '22 at 09:17
  • @Someprogrammerdude Yes, I do want 100010 empty vectors. The vectors here were just used as an example to show when the problem will appear. I know the difference between vectors and arrays. – Sheng Horizon Nov 18 '22 at 13:41
  • Can you please include the full and complete build log from this example in your question? Also please try to build with the `-v` flag to get verbose output from the compiler, which could give further information. – Some programmer dude Nov 18 '22 at 13:52
  • @Someprogrammerdude OK /var/folders/46/gnq0_xf15dj0d3drfw04nz7c0000gn/T//ccGl2TIh.s:477:29: error: unexpected token in '.section' directive .section .data.rel.ro.local ^ – Sheng Horizon Nov 18 '22 at 14:13
  • But the rest of it is too long, how can I post it out? – Sheng Horizon Nov 18 '22 at 14:14
  • Please [edit] your question to include the full and complete build output (with verbose option turned on). – Some programmer dude Nov 18 '22 at 14:15
  • To me it looks like a mismatch between the GCC compiler and its generated object files, and the Clang linker which doesn't quite recognize all the data in those object files. – Some programmer dude Nov 21 '22 at 08:14
  • @Someprogrammerdude Thank you so much. Would you mind telling me what maybe I should do? – Sheng Horizon Dec 28 '22 at 00:21

1 Answers1

1

if you try with g++, add these options: -O2 -Wall -lm

chongin12
  • 11
  • 2
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 27 '23 at 12:39
  • just `-O2` is sufficient. – Dushyant Singh May 08 '23 at 18:53