Блог пользователя proRam

Автор proRam, история, 5 лет назад, По-английски

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?

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 лет назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

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.

»
4 года назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

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++.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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++.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Look here

  • »
    »
    4 года назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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.

      • »
        »
        »
        »
        4 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

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

        • »
          »
          »
          »
          »
          4 года назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          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?

          • »
            »
            »
            »
            »
            »
            4 года назад, # ^ |
            Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

            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"
            }
            
            • »
              »
              »
              »
              »
              »
              »
              4 года назад, # ^ |
                Проголосовать: нравится 0 Проголосовать: не нравится

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

            • »
              »
              »
              »
              »
              »
              »
              4 года назад, # ^ |
                Проголосовать: нравится 0 Проголосовать: не нравится

              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.

          • »
            »
            »
            »
            »
            »
            4 года назад, # ^ |
              Проголосовать: нравится 0 Проголосовать: не нравится

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

            • »
              »
              »
              »
              »
              »
              »
              4 года назад, # ^ |
                Проголосовать: нравится 0 Проголосовать: не нравится

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

              • »
                »
                »
                »
                »
                »
                »
                »
                4 года назад, # ^ |
                  Проголосовать: нравится 0 Проголосовать: не нравится

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

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  4 года назад, # ^ |
                    Проголосовать: нравится 0 Проголосовать: не нравится

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

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  4 года назад, # ^ |
                    Проголосовать: нравится 0 Проголосовать: не нравится

                  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.

»
3 года назад, # |
Rev. 4   Проголосовать: нравится +5 Проголосовать: не нравится

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

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++-12 or which g++-11 for specific versions. Then paste the result in the "C++ Compiler" box for Clion as shown in the image.

image

Alternatively, paste content from https://raw.githubusercontent.com/tekfyl/bits-stdc-.h-for-mac/master/stdc%2B%2B.h in your bits/stdc++.h file (within a visible directory like /Library/Developer/CommandLineTools/.... )