0

I am using g++ to compile a C++ program. I am using the g++ installed through Homebrew (currently g++-13). Now, I installed llvm through homebrew, and for some reason, it doesn't link it due to some conflicts with Mac's llvm I guess. I read somewhere we need to have LDFLAGS="-L$HOMEBREW_PREFIX/opt/llvm/lib/c++ -Wl, rpath,$HOMEBREW_PREFIX/opt/llvm/lib/c++"

So, for echo $LDFLAGS I get,

-L/opt/homebrew/opt/llvm/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm/lib/c++

But, using g++ -std=c++17 -o x x.cpp -fsanitize=address -g I get the following error:

ld: library not found for -lasan
collect2: error: ld returned 1 exit status

Can someone please help me to resolve this? I am using MacOS Ventura 13.3.1.

  • 1
    Might just not be supported https://github.com/orgs/Homebrew/discussions/3384 – Alan Birtles May 22 '23 at 06:34
  • Seems like it :( – Vedanta Mohapatra May 22 '23 at 06:42
  • 2
    Just use apple clang, much easier to use a platforms built in tools – Alan Birtles May 22 '23 at 06:43
  • Yeah, that seems to be working, but the thing is, I am using this for Competitive Programming. So, I am using headers like bits/stdc++, policy Based Data Structures, which are not supported by Clang. – Vedanta Mohapatra May 22 '23 at 06:49
  • 3
    See https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h – Alan Birtles May 22 '23 at 06:53
  • The widespread cargo cult of using is awful. But from where you took that one *has* to use such non-standard header for to participate on those sites? – Öö Tiib May 22 '23 at 07:30
  • @ÖöTiib If you use standard header files. Then either you have to keep several header files in your code as a template of some sort, so it saves time. Or just have to include them as you require them. As for policy-based data structures. Those are a bit difficult to emulate. You need to write your own version for it to work. I usually never use bit/stdc++.h for anything other than online websites as it doesn't have any bad implications in those websites, like even the top-rated coder there uses it. I am talking about Codeforces like websites. But I understand where proper C++ devs come from. – Vedanta Mohapatra May 22 '23 at 07:57
  • The policy based data structures of gcc are non-standard, so if you need those then better buy a Linux machine for debugging your code. Apple is hardware vendor that wants also to own, control and tax the market of software that runs on its hardware. Therefore it is guaranteed that there will be obstacles for features of gcc. – Öö Tiib May 22 '23 at 08:51

0 Answers0