compiler gives me error message " boost/smart_ptr.h: No such file ordirectory"

P

Pallav singh

Hi All ,

while compiling the following code my compiler gives me error message
" boost/smart_ptr.h: No such file or directory" . do i need to give
some comiplation option for it ...such as where to find header file
g++ -g file.cc

#include<iostream>
#include "boost/smart_ptr.h"
using namespace std;

class A
{
int a,b;
public :
void printf()const
{ cout<<" value of a "<<a <<"Value of b "<<b <<endl ;}
};

int main()
{
boost::shared_ptr< A > sample(new A);
printf("The Sample now has %i references\n", sample.use_count());

boost::shared_ptr< A > sample2 = sample;
printf("The Sample now has %i references\n", sample.use_count());

sample.reset();
printf("The Sample now has %i references\n", sample2.use_count());

return 0;
}

Thanks
Pallav Singh
 
G

Gert-Jan de Vos

Hi All ,

while compiling the following code my compiler gives me error message
"  boost/smart_ptr.h: No such file or directory" . do i need to give
some comiplation option for it ...such as where to find header file

Try: #include <boost/smart_ptr.hpp>

You may need to add the -I option with the path where your boost
library is installed, if not already present in the INCLUDE
environment
variable.
 
J

James Kanze

Try: #include <boost/smart_ptr.hpp>

That shouldn't change anything. The standard says that when
using #include "...", if the search fails, the directive is
reprocessed as if it were #include said:
You may need to add the -I option with the path where your
boost library is installed, if not already present in the
INCLUDE environment variable.

He definitely needs to tell the compiler where to look for the
headers, if they aren't installed in the "standard places".
What the standard places are, of course, depends on the
compiler; for g++, it's derived from where the compiler itself
is installed, with the adjunction (at least under Unix) of
"/usr/include", and maybe "/usr/local/include".
 
G

Gert-Jan de Vos

That shouldn't change anything.  The standard says that when
using #include "...", if the search fails, the directive is
reprocessed as if it were #include <...>.

..hpp rather than .h might make the difference..
 
J

James Kanze

.hpp rather than .h might make the difference..

Using the correct name of the file is a requirement, yes:).
I'd missed that you'd changed the name of the file, as well as
changing the form from "..." to <...>. (And generally, if Boost
is correctly installed, you probably should consider it part of
the "implementation", so <...> would be more appropriate.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top