0

When I am trying to run the following code

#include<bits/stdc++.h>
using namespace std; 


int main() 
{
    int n;
    cin>>n;
    vector<vector<int>> v(n, vector<int>(2));
    cout<<2<<"\n";
    return 0; 
}

using the command g++ file.cpp then it is giving the following error

0  0x1022a41a0  __assert_rtn + 140
1  0x10212ba8c  mach_o::relocatable::Parser<arm64>::parse(mach_o::relocatable::ParserOptions const&) + 4536
2  0x1020fdd38  mach_o::relocatable::Parser<arm64>::parse(unsigned char const*, unsigned long long, char const*, long, ld::File::Ordinal, mach_o::relocatable::ParserOptions const&) + 148
3  0x1021664ac  ld::tool::InputFiles::makeFile(Options::FileInfo const&, bool) + 1468
4  0x102169360  ___ZN2ld4tool10InputFilesC2ER7Options_block_invoke + 56
5  0x1c17b41f4  _dispatch_client_callout2 + 20
6  0x1c17c8f8c  _dispatch_apply_invoke_and_wait + 224
7  0x1c17c826c  _dispatch_apply_with_attr_f + 1152
8  0x1c17c847c  dispatch_apply + 108
9  0x1021691f4  ld::tool::InputFiles::InputFiles(Options&) + 616
10  0x1020eb6c0  main + 552
A linker snapshot was created at:
        /tmp/a.out-2022-09-19-011653.ld-snapshot
ld: Assertion failed: (_file->_atomsArrayCount == computedAtomCount && "more atoms allocated than expected"), function parse, file macho_relocatable_file.cpp, line 2061.
collect2: error: ld returned 1 exit status
Omhari
  • 9
  • 2
  • 2
    Can't reproduce. First it fails to compile because `` is not found ([you should not use it anyway](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h)). Then it fails with a syntax error on `vector>` because you need a space between the `>>`. Fixing both of those, it compiles and links just fine. `g++ -v` here is Apple clang 14.0.0. – Nate Eldredge Sep 18 '22 at 19:59
  • 1
    @NateEldredge `vector>` is valid syntax in C++11 and later. Nobody should still compile in C++98 standard anymore, although this is strangely still the default in Clang. – prapin Sep 18 '22 at 20:11
  • Okay, but nonetheless that's what OP said they were using, so they should have got the same error. – Nate Eldredge Sep 18 '22 at 20:13
  • @Omhari What does `g++ -v` returns on your platform? As @NateEldredge correctly wrote, the infamous `` header is not present in Apple Clang distribution (and never will be). You are probably using a real GCC compiler, installed somehow differently (maybe Homebrew). – prapin Sep 18 '22 at 20:17
  • @prapin It is returning gcc version 12.2.0 (Homebrew GCC 12.2.0). I installed gcc using homebrew. Same setup was working fine with intel chip mac. – Omhari Sep 18 '22 at 20:30
  • Does this answer your question? [Why should I not #include ?](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) – Taekahn Sep 18 '22 at 21:29
  • I tried replacing with and but still giving the same error. – Omhari Sep 19 '22 at 03:16
  • 1
    @Omhari There is an open support ticket about this issue with apple support, but their response is to stop using the bits include. If that isn’t working for you, The other alternative solution mentioned on the issue is downgrading to Xcode 13. – Taekahn Sep 19 '22 at 03:30
  • @Omhari I am pretty sure you found a bug in GCC 12.2 linker, which makes this an important question. But two things distracted the readers and made them misunderstood your problem. First, you used the infamous `` header. Most C++ programmers **hate** to see that header used, and will suppose immediately that this is the problem, even when it does not make sense like here. Second, you didn't mention before your answer in comment that you are using Homebrew GCC. Apple computer programmers like me made the assumption that you were using Apple Clang, which comes with Xcode. – prapin Sep 19 '22 at 07:41
  • Duplicates: https://stackoverflow.com/q/73732838, https://stackoverflow.com/q/73714336 – prapin Sep 19 '22 at 11:30
  • Thanks @prapin it worked when i downgreaded my Command Line Tools from verson 14 to version 13.4. I followed setps specified in https://stackoverflow.com/questions/73714336/xcode-update-to-version-2395-ld-compile-problem-occurs-computedatomcount-m – Omhari Sep 20 '22 at 13:54

0 Answers0