0

I think I have boost installed properly so I am trying to use the test "first.cpp" found here:

#include<iostream>
#include<boost/any.hpp>

int main()
{
    boost::any a(5);
    a = 7.67;
    std::cout<<boost::any_cast<double>(a)<<std::endl;
}

And I get the following:

Jason@ITHAKA-DB44CFE1 /home/jason
$ g++ -o first first.cpp
first.cpp:2:24: boost/any.hpp: No such file or directory
first.cpp: In function `int main()':
first.cpp:6: error: `boost' has not been declared
first.cpp:6: error: `any' undeclared (first use this function)
first.cpp:6: error: (Each undeclared identifier is reported only once for each
unction it appears in.)
first.cpp:6: error: expected `;' before "a"
first.cpp:7: error: `a' undeclared (first use this function)
first.cpp:8: error: `boost' has not been declared
first.cpp:8: error: `any_cast' undeclared (first use this function)
first.cpp:8: error: expected primary-expression before "double"
first.cpp:8: error: expected `;' before "double"
first.cpp:9:2: warning: no newline at end of file

Jason@ITHAKA-DB44CFE1 /home/jason
$

Where my boost library is in my ./home/Jason/

Obviously something is up. Also, all the boost libraries themselves use this "boost/..." so for some reason either:

1 - I did something wrong with Boost 2 - C++/gcc is not "seeing" my boost

any input?

0

2 Answers 2

2

You need to pass -I/home/Jason/include to gcc, and probably a -L/home/Jason/lib too, because the library is not installed in the standard path. Try:

 g++ -I/home/Jason/include -L/home/Jason/lib -o first first.cpp

Also, once compiled, it will not run properly because the libraries are not in the standard path again. To run it, you need to add /home/Jason/lib to the environment variable LD_LIBRARY_PATH.

Edit: As Tony D pointed out, you can set CPLUS_INCLUDE_PATH to /home/Jason/include instead, which is equivalent to the compiler option I gave you.

Edit

If you only want to test your install, you can run the ~/bin/Boost.Test script (assuming you had --with-libraries=test enabled when you installed it). Otherwise there should be a bin directory in hour home (if you used that as prefix), if there is anything with the name Boost in it, try to run it (but remember to set the LD_LIBRARY_PATH before).

9
  • what is the "standard path"? I would rather just have it there.
    – jason m
    Apr 23, 2013 at 2:07
  • Yes, you can leave it there, but then you need to tell GCC where to look for it.
    – Thibaut
    Apr 23, 2013 at 2:10
  • how do i know if it is properly installed? is there anything i can do outside the above? how do i tell gcc where to look
    – jason m
    Apr 23, 2013 at 2:10
  • by adding the flags i just told you
    – Thibaut
    Apr 23, 2013 at 2:12
  • You can set CPLUS_INCLUDE_PATH in your environment, adding the boost path (you want to include the versioned directory above "boost" as you'll be using #include <boost/xxx>). Apr 23, 2013 at 2:14
-1
  • header files link to '/usr/include'

$ cd /usr/include
$ sudo ln -s /usr/local/boost_xxxx/boost boost

  • compile boost library, and copy the so files to '/usr/lib'

$ sudo cp /usr/local/lib/libboost_regex-gcc41-mt-xxxx.so.xxxx /usr/lib/

4
  • I assume he installed it in his home directory because he couldn't do otherwise. But this would work, so would installing boost directly in the standard path ;)
    – Thibaut
    Apr 23, 2013 at 2:18
  • 1
    @jasonm the standard path is where the compiler looks for system headers and libraries. This is where anything you install using the package manager will end up. It varies from system to system, but usually the main ones are /usr and /usr/local.
    – Thibaut
    Apr 23, 2013 at 2:22
  • so i guess my concern here is really if i installed it properly. i ran the bootstrap.cmd and it seemed okay. is there anything else i need to do? really, i am not 100% convinced that I did this correctly. I am doing this to indeed check if it "installed" correctly.
    – jason m
    Apr 23, 2013 at 2:22
  • i edited my reply, i didn't understand that you just wanted to test it.
    – Thibaut
    Apr 23, 2013 at 2:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.