1

I have the boost library in my downloads folders. When I tried to include a particular file. It is throwing errors. Below is the code and the steps I did.

\main.cpp

#include "type_index.hpp" int main(){ //some code return 0; } 

I opened the command prompt and ran the following command

g++ -IC:\Users\Owner\Downloads\boost_1_70_0\boost -o main main.cpp 

I got the following error in command prompt

In file included from main.cpp:2:0: C:\Users\Owner\Downloads\boost_1_70_0\boost/type_index.hpp:17:28: fatal error: boost/config.hpp: No such file or directory #include <boost/config.hpp> ^ compilation terminated. 

How can I run the above file? Do I have to change the location of boost directory from downloads folder to some where within mingw directories?

Adding the picture of directory: enter image description here

6
  • What is the contents of C:\Users\Owner\Downloads\boost_1_70_0\boost? Is there a sub-directory named boost? Commented Jun 7, 2019 at 5:49
  • yes. I will include the pic of the directory Commented Jun 7, 2019 at 5:50
  • 1
    That directory for amending to the include path should be -IC:\Users\Owner\Downloads\boost_1_70_0 . All the boost headers look for the boost root as part of their specified file name. Likewise, your source shoud do the same, and thus your source is wrong. it should say #include <boost/type_index.hpp>. Fix your include path, preface all your source file references to boost headers with boost/, and you should be good to go. Commented Jun 7, 2019 at 5:51
  • And related, that pic now-posted is not the directory @Someprogrammerdude asked about. He specifically asked what the content of C:\Users\Owner\Downloads\boost_1_70_0\boost was; you showed the content of C:\Users\Owner\Downloads\boost_1_70_0. There's a reason he asked, and it directly relates to my prior comment. Commented Jun 7, 2019 at 5:55
  • @WhozCraig Thanks its working. For future c/c++ beginners it will be helpful if you "answer it". And I will mark it is as a answer. Commented Jun 7, 2019 at 5:59

1 Answer 1

2

Assuming boost is correctly configured and built on your system, there will be a location where the hub of the boost include root is located. Ex: if you downloaded and built boost in c:\Stuff\boost_1_70_0, then within that folder will be the hub of the boost include set, c:\Stuff\boost_1_70_0\boost, and it contains all of the boost headers.

boost is referenced by amending the include path to provide access to the boost include hub; not to provide access to the top-most headers in the hub. Similar to openssl, boost prefaces all of their header includes in their own headers, with boost/. The consumers of boost should do the same, Therefore, the include path must include the folder where the boost/ hub can be found. It should not include the boost/ hub itself as part of the path.

Ex: This is correct

g++ -Ic:\Stuff\boost_1_70_0 -o main main.cpp 

This, on the other hand is wrong:

g++ -Ic:\Stuff\boost_1_70_0\boost -o main main.cpp 

With the former, when code includes:

#include <boost/asio.hpp> 

the include path is searched, and the file is found. Further, within that header, when the compiler see this:

#include <boost/asio/associated_allocator.hpp> 

it can still resolve correctly, because dropping that "thing" on the end of one of the folders in the include path works.

Now, consider the wrong case. What happens if you configure the include path to accidentally specify the boost/root hub itself? Well, now you can do this:

#include <asio.hpp> 

But as soon as the preprocessor starts in on that header it will see:

#include <boost/asio/associated_allocator.hpp> 

Um.. woops. The pre-processor will look for this and never find it

Summary

When using boost headers in your source, you always refer to them with the boost hub preamble:

#include <boost/headername.hpp> 

and always include the folder where the boost/ hub is located in your build configuration as an amended include path; not full path including the boost/ hub.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, hanks for the answer and Sorry for being ignorant.. What is meaning of "configured and built"?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.