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

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

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
  • Проголосовать: не нравится

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

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

»
6 лет назад, скрыть # |
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.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +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++.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 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.

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

Simply installing gcc with homebrew worked for me: brew install gcc@13

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++-13. 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/.... )