### proRam's blog

By proRam, history, 3 years ago,

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
#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

| Write comment?
 » 3 years ago, # |   0 Auto comment: topic has been updated by proRam (previous revision, new revision, compare).
 » 3 years ago, # | ← 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.
 » 3 years ago, # |   +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++.
•  » » 3 years ago, # ^ |   0 Hey Parth, I tried using g++-10.0.0 on mac, but it doesn't work. Showing that this is invalid command.
•  » » » 3 years ago, # ^ | ← Rev. 2 →   +1 Did you install gcc? If yes, use the command g++-10 and not g++-10.0.0
•  » » » » 17 months ago, # ^ |   0 I can't thank you enough! your comment has helped me a lot!
•  » » » » 9 months ago, # ^ |   0 where should i use the command
•  » » 4 months ago, # ^ |   0 Still not working
 » 3 years ago, # |   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.
•  » » 3 years ago, # ^ |   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++.
•  » » 3 years ago, # ^ |   0 Look here
•  » » 3 years ago, # ^ | ← Rev. 2 →   0 Reinstall homebrew, xcode-command line tool, and the compiler
•  » » » 3 years ago, # ^ |   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.
•  » » » » 3 years ago, # ^ |   0 Install the extension acmx in VSCode, you even will have a button to submit.
•  » » » » » 3 years ago, # ^ |   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?
•  » » » » » » 3 years ago, # ^ | ← 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" } 
•  » » » » » » » 3 years ago, # ^ |   0 I've only downloaded homebrew. Where do you recommend I download gcc 9 or 10 for mac?
•  » » » » » » » » 3 years ago, # ^ |   0 With homebrew. Write on a terminal: brew install gcc
•  » » » » » » » 3 years ago, # ^ |   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.
•  » » » » » » » » 3 years ago, # ^ |   0 In your extensions.
•  » » » » » » 3 years ago, # ^ |   0 Ignore that about env.sh, it’s not necessary as we will configure it on the acmx extension.
•  » » » » » » » 3 years ago, # ^ |   0 So now Im all set and I just need to download the acmx extension?
•  » » » » » » » » 3 years ago, # ^ |   0 If you have installed gcc, then, it just remains to download acmx extension and configure it appropriately.
•  » » » » » » » » » 3 years ago, # ^ |   0 where do I type "\$HOME/.acmx/languages/cpp.json" this in
•  » » » » » » » » » 3 years ago, # ^ |   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.
 » 17 months ago, # | ← Rev. 3 →   +5 Simply installing gcc with homebrew worked for me: homebrew install gccSince 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.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/.... )
»
8 months ago, # |
0