proRam's blog

By proRam, history, 2 years ago, In English

I am facing issue in using the Policy Based Data Structures in C++ as the following errors occur. So far I have tried:

1) Updated and used GCC

$ gcc NONAME00.cpp
NONAME00.cpp:8:10: fatal error: 'ext/pb_ds/assoc_container.hpp' file not found
#include <ext/pb_ds/assoc_container.hpp>
         ^~~~~~~~~~~~
1 error generated.

2) Updated and used G++

$ g++ NONAME00.cpp
NONAME00.cpp:8:10: fatal error: 'ext/pb_ds/assoc_container.hpp' file not found
#include <ext/pb_ds/assoc_container.hpp>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

3) Added the files <ext/pb_ds/assoc_container.hpp> and <ext/pb_ds/tree_policy.hpp> to respective locations and then again compiled with gcc and g++.

Can anyone tell me the solution to this?

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

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

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

»
2 years ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

Firstly, gcc is a C compiler. But, it can compile C++ programs just fine. To do so, you should link your file to the STL. To do so, you'd be looking at something like this:

gcc [compilation flags] -lstdc++

Instead, just use g++, as you don't need to type -lstdc++, and because it is the C++ compiler provided by GNU Compiler Collection.

Secondly, your error is stated clear: file not found. Either you've not set the compiler to look for the pbds headers in the right directories (if you're using an IDE of some sort that let's you add all directories you want the compiler to search in) or you don't have the headers downloaded. Try including the files with their complete file path like so:

#include "C:/Programming/MinGW/MinGW 9.2.0/include/c++/ext/pb_ds/...."

This is how it'd look on my system if I included using entire file path. You should put your file path correctly.

Also, AFAIK, pbds is not directly available on macOS. I don't know much about it in that respect (I'm a Windows user). Googling stuff brings this up.

»
2 years ago, # |
  Vote: I like it +10 Vote: I do not like it

In macos, gcc and g++ are both linked to clang. Try installing gcc through homebrew and use a command like g++-9 (which is the g++ version I installed) instead of just g++.

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

    Hey Parth, I tried using g++-10.0.0 on mac, but it doesn't work. Showing that this is invalid command.

    • »
      »
      »
      2 years ago, # ^ |
      Rev. 2   Vote: I like it +1 Vote: I do not like it

      Did you install gcc? If yes, use the command g++-10 and not g++-10.0.0

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

        I can't thank you enough! your comment has helped me a lot!

      • »
        »
        »
        »
        7 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        where should i use the command

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

Im having the exact same problem but I use vs code(g++) on a mac. I also tried replacing the files but it kept on claiming that more files were not found. If someone can help that would be great.

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

    There's a difference between the compiler and the C++ standard library implementation. G++ (GCC) is a compiler which uses it's own C++ standard library implementation — libstdc++.

    So you need to add libstdc++ to your include directories in order to use those files. So first install libstdc++ successfully (it should be added to path automatically). To see include directories pass -H flag to the compiler and see if libstdc++ is in your path.

    Easiest way to check installation of libstdc++ would be to use clang with -stdlib=libstdc++.

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

    Look here

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

    Reinstall homebrew, xcode-command line tool, and the compiler

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

      I have a question, If I install these things when I want to run my code can I just press a button and then I place my input or do I have to write some code before compiling? Sorry, im new to this because I would prefer if I just pressed a button rather than writing things before running my programming.

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

        Install the extension acmx in VSCode, you even will have a button to submit.

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

          I already installed homebrew and now im confused on what to do because it says "To be able to compile files from your terminal you can add the following alias in your env.sh file." but I don't have a env.sh file. Also if I regret my decision can I undo all of this quickly or delete it?

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

            I think you can undo. But it’s not necessary. Have you installed gcc (9 or 10)? If you haven’t, then do it. If you have, then I recommend you install this extension.

            once you’ve installed the extension, you can go to cpp.json file on the extension directory ($HOME/.acmx/languages/cpp.json) and write g++-9 (or g++-10), and also -std=c++11. For more info visit the wiki of the extension.

            this is how my cpp.json looks:

            {
               "preRun":{
                   "g++-9",
                   "-fdiagnostics-color=always",
                   "-std=c++11",
                   "-DACMX",
                   "$CODE",
                   "-o",
                   "$OUTPUT",
                   "--debug"
               }
               "run": ["$OUTPUT"],
               "ext": "cpp"
            }
            
            • »
              »
              »
              »
              »
              »
              »
              2 years ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              I've only downloaded homebrew. Where do you recommend I download gcc 9 or 10 for mac?

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

                With homebrew. Write on a terminal: brew install gcc

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

              When I go to home in vs code I don't see acmx. Where do I find the extension directory? I only find ACMX:edit language not languages.

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

            Ignore that about env.sh, it’s not necessary as we will configure it on the acmx extension.

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

              So now Im all set and I just need to download the acmx extension?

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

                If you have installed gcc, then, it just remains to download acmx extension and configure it appropriately.

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

                  where do I type "$HOME/.acmx/languages/cpp.json" this in

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

                  Open a terminal, type: open ..., the dots represent the path of cpp.json (that one I gave you above).

                  Read the wiki of the acmx extension.

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

                  When ever I open "$HOME/.acmx/languages/cpp.json" It directs me to xcode but not vs code.

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

Simply installing gcc with homebrew worked for me: homebrew install gcc

Since I use CLion, I also had to update the compiler in the settings.

To find out the location of your installed gcc, type: which g++ or which g++-11 for specific versions. Then paste the result in the "C++ Compiler" box for Clion as shown in the image.

image

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

include <bits/extc++.h>