0

I am trying to include the following headers:

#include <libs/serialization/example/portable_binary_iarchive.hpp>
#include <libs/serialization/example/portable_binary_oarchive.hpp>

These files are located in a path like:

/home/nobody/boost_1_45_0/libs/serialization/example/portable_binary_iarchive.hpp

In my Makefile, I have added:

-I/home/nobody/boost_1_45_0/libs

However, when I compile, I get the error messages like:

error: libs/serialization/example/portable_binary_iarchive.hpp: No such file or directory

Can anybody tell me what I am doing wrong here? I am also including boost libraries like

#include <boost/archive/binary_oarchive.hpp>

However, to get those, it is sufficient to do in my Makefile:

-I/usr/include/boost

Why doesn't this work for the headers in the other location? How should I change my Makefile? The first statement current looks like this:

test: test.o 
    g++ -O3 -ffast-math -funroll-loops -ansi -pedantic-errors -L/usr/lib -lboost_filesystem -lboost_serialization -lboost_iostreams -lz -I/usr/include/boost -I/home/nobody/boost_1_45_0/libs -o test test.o
user788171
  • 16,753
  • 40
  • 98
  • 125

1 Answers1

2

To get

#include <libs/serialization/example/portable_binary_iarchive.hpp>

from directory

/home/nobody/boost_1_45_0/libs/serialization/example/portable_binary_iarchive.hpp

your Makefile needs

-I/home/nobody/boost_1_45_0

Notice that I omitted the /libs from the end. That's because your #include directive already lists that directory.


As for your second example, is the file you want at this location:

/usr/include/boost/boost/archive/binary_oarchive.hpp
                   ^^^^^ (repeated boost here)

If not g++ is likely defaulting to /usr/include as the search space for

#include <boost/archive/binary_oarchive.hpp>

Ie., your

-I/usr/include/boost

is useless to the compiler.

chrisaycock
  • 36,470
  • 14
  • 88
  • 125
  • I just tried this and it did not work even after I removed libs from the end of the -I path, same error is still showing up. Also -I/usr/include/boost is probably not necessary, I removed it and it didn't seem to change anything. If it matters, #include is in a header file that is included in my top level .cpp file. – user788171 Aug 08 '12 at 02:29
  • @user788171 Thinking of it of some more, it's really odd that you're including a header from the *example* directory. Is what you actually want in `/home/nobody/boost_1_45_0/include/serialization/...`? I notice the [example file](http://www.boost.org/doc/libs/1_38_0/libs/serialization/example/portable_binary_iarchive.hpp) includes other Boost headers, which is what you should really be doing. – chrisaycock Aug 08 '12 at 02:40
  • Yea, I actually want to use the headers in example, I'm making a derived class based off of the one in the example. – user788171 Aug 08 '12 at 02:44
  • @user788171 If you really have your heart set on using the example file like that, all I can advise is to make sure you've spelt your path correctly. My above answer should work if the file is in that directory. – chrisaycock Aug 08 '12 at 02:58
  • @user788171, did you remove `libs` or `/libs`? – Beta Aug 08 '12 at 20:33
  • @Beta, that's irrelevant, the result would be the same. – Jonathan Wakely Aug 09 '12 at 08:09
  • @user788171, if the suggestion doesn't work then either you didn't do it right or the error you're getting now is actually slightly different. For those files you probably want to simply `#include ` and then use `-I/home/nobody/boost_1_45_0/libs/serialization/example/`, there's no benefit to having that path in the `#include` directive, it just makes it harder to move the files and include them in a different location – Jonathan Wakely Aug 09 '12 at 08:13