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?
Auto comment: topic has been updated by proRam (previous revision, new revision, compare).
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.
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++.
Hey Parth, I tried using g++-10.0.0 on mac, but it doesn't work. Showing that this is invalid command.
Did you install gcc? If yes, use the command g++-10 and not g++-10.0.0
I can't thank you enough! your comment has helped me a lot!
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.
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 installlibstdc++
successfully (it should be added to path automatically). To see include directories pass-H
flag to the compiler and see iflibstdc++
is in your path.Easiest way to check installation of
libstdc++
would be to use clang with-stdlib=libstdc++
.Look here
Reinstall homebrew, xcode-command line tool, and the compiler
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.
Install the extension acmx in VSCode, you even will have a button to submit.
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?
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:
I've only downloaded homebrew. Where do you recommend I download gcc 9 or 10 for mac?
With homebrew. Write on a terminal:
brew install gcc
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.
In your extensions.
Ignore that about env.sh, it’s not necessary as we will configure it on the acmx extension.
So now Im all set and I just need to download the acmx extension?
If you have installed gcc, then, it just remains to download acmx extension and configure it appropriately.
where do I type "$HOME/.acmx/languages/cpp.json" this in
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.
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
orwhich 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/.... )