1
votes

I have a small test case program just to see if boost works on some system.

#include <iostream>
#include <boost/math/distributions/normal.hpp>
#include <boost/math/distributions/chi_squared.hpp>

using namespace std;

int main(int argc, char* argv[]) {

    // Boost test
    boost::math::normal std_normal;
    double x = 1.5;
    cout << boost::math::cdf(std_normal, x) << endl;

    boost::math::normal non_std_normal(1.5, 2);

    cout << boost::math::cdf(non_std_normal, x) << endl; // should output 1/2

    // Test the chi-squared inverse
    int degree_of_freedom = 19;
    boost::math::chi_squared chi_dist(degree_of_freedom);
    cout << boost::math::quantile(complement(chi_dist, 0.05)) << endl;

    return 0;
}

I ssh to some server and they only allow me to use boost libraries through some directory full of shared objects and archive files (i.e. libboost_log.so, libboost_math_c99.a, etc.).

To be honest, I have no clue how to use these files. I tried (for both g++ and gcc)

g++ test.cpp -o test -l /share/apps/boost/1.55.0/lib

g++ test.cpp -o test -l /share/apps/boost/1.55.0/lib -lboost_system -lboost_filesystem

g++ -std=c++11 -pedantic test.cpp -I/share/apps/boost/1.55.0/include/ -o test

g++ test.cpp -o test -I /share/apps/boost/1.55.0/include -lboost_system -lboost_filesystem

where /share/apps/boost/1.55.0/lib is the directory for the .so and .a files and /share/apps/boost/1.55.0/include is the directory for the .hpp files.

I was denied permission for the 3rd command with the following output:

In file included from /share/apps/boost/1.55.0/include/boost/math/special_functions/detail/round_fwd.hpp:11:0, from /share/apps/boost/1.55.0/include/boost/math/special_functions/math_fwd.hpp:26, from /share/apps/boost/1.55.0/include/boost/math/special_functions/erf.hpp:13, from /share/apps/boost/1.55.0/include/boost/math/distributions/normal.hpp:19, from test.cpp:12: /share/apps/boost/1.55.0/include/boost/config.hpp:30:29: fatal error: /share/apps/boost/1.56.0/build/boost_1_56_0/boost/config/user.hpp: Permission denied

I received the error for the fourth command:

fatal error: boost/math/distributions/normal.hpp: No such file or directory.

1
you should use -L for library path, but you do need the headers to be readable by you. - swang
it does look like i have permission to read it ... I am not sure what the problem is :/. I tried to #include "/share/apps/boost/1.55.0/include/boost/math/..." directly but it didn't work because it references another .hpp file with #include <boost/...> - itzjustricky
Can you compile boost yourself on the target machine and link to your own shared libraries? Or maybe copy the files compiled on your primary workstation? - Marcin
Yes. My original plan was just to compile on my workstation and then execute my program on the server, but I received the following error: ./scrub: error while loading shared libraries: libboost_program_options.so.1.54.0: cannot open shared object file: No such file or directory But I am not sure I understand your first question. Sorry I am a bit inexperienced as a programmer. - itzjustricky

1 Answers

1
votes

you want to use

g++ -isystem /share/apps/boost/1.55.0/include -L /share/apps/boost/1.55.0/lib test.cpp -o test -lboost_system -lboost_filesystem

-isystem tells the compiler where to look for system header files. And -L tells the linker where to look for libraries. It's not obvious if you need the boost filesystem or system libraries based on your code snippet.

If you're unable to read the boost headers or shared libraries on the remote server, this is unrelated to your question. Contact your sys admin for help.