robell's blog

By robell, history, 2 months ago, In English
Recently, I came across this snippet of code:
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

which implements a policy based data structure. Yet when I ran it on VS code on my Mac(pls don't judge), the code kept on giving me errors stating that "assoc_container.hpp not found" ect.. I searched online for the source code for the ext folder that assoc_container is located in yet the only thing that I could find is this link which doesn't contain a pb_ds folder. For the people who use policy based data structures, do you guys know whether there is anything I can do so that I'm able to implement these policy based data structures?

PS:I've looked at this blog post Post,but I wasn't gain a verifiable answer on what to do since I'm small brained. I also compile my code with "gcc --std=c++17 $x -o $lol" where $x is the file name of the cpp file and $lol is the output file name.

 
 
 
 
  • Vote: I like it
  • +1
  • Vote: I do not like it

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by robell (previous revision, new revision, compare).

»
2 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

brew install gcc

And alias the newly downloaded g++ (if you do it now, it's g++-11) in use/local/bin to g++ and run g++ A.cpp and you should be fine.

If things go crazy and it still doesn't work, go to usr/local/bin and delete g++/c++ directories and re run the command.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Recently I purchased a M1 Macbook and was facing this issue. I'm not very tech savvy but luckily i was able to sort this out.

I'll explain how I sorted through this using brew ahead.

  • Install Brew using this link Download Brew
  • Update your path in order to access brew from command line. This is a bit tricky if you don't know vim (you can use any editor of choice). I'll explain this in the next points.
  • Open terminal. If you use ohmyzsh type in vim ~/.zshrc otherwise use your standard profile (perhaps it is .bashrc, which could be opened with vim ~/.bashrc.
  • Paste export PATH=/opt/homebrew/bin:$PATH somewhere in your profile(bashrc or zshrc etc), then restart your terminal.
  • Via your command line install GCC by typing the command brew install gcc , then restart terminal once it is installed.
  • Once again, open your profile and on the bottom type this — alias g++="g++-11" (Note the this isn't a neccessary step, you can skip it. In such case, remember to use g++-11 while compiling)and restart your terminal for the last time.

Voila, you are done. Now you should be able to use pbds

To confirm everything is working fine run the command g++ --version or g++-11 --version depending on how you used alias. If you see homebrew g++-11, you are good to go!

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    ld: warning: dylib (/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11/libstdc++.dylib) was built for newer macOS version (11.3) than being linked (11.0)

    This is what I got when I was running a file with "g++-11 filename.cpp". And if we simply run with g++ it would give the same error 'ext/pb_ds/assoc_container.hpp" file not found.

    I updated gcc with "brew install gcc" and also exported path in both zshrc & bashrc. Are the above ways only valid for MacBook M1, because I am using MacBook Air?

    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      ld: warning: dylib (/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11/libstdc++.dylib) was built for macOS version (11.3) than being linked (11.0)

      Perhaps your macOS is outdated. Either install a gcc version from homebrew that supports your OS version or update your OS.

  • »
    »
    2 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Thanks a bunch! It finally worked.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I am sorry I know this is irrelevant but this line is sooo funny :

"I ran it on VS code on my Mac(pls don't judge)"