【问题标题】:Compiling a program that is dependent on boost libraries with only .so or .a files编译依赖于只有 .so 或 .a 文件的 boost 库的程序
【发布时间】:2015-02-16 01:56:39
【问题描述】:

我有一个小测试用例程序,只是为了查看 boost 是否适用于某些系统。

#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;
}

我 ssh 到某个服务器,它们只允许我通过一些充满共享对象和存档文件(即 libboost_log.so、libboost_math_c99.a 等)的目录使用 boost 库。

说实话,我不知道如何使用这些文件。 我试过(对于 g++ 和 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

其中 /share/apps/boost/1.55​​.0/lib 是 .so 和 .a 文件的目录 /share/apps/boost/1.55​​.0/include 是 .hpp 文件的目录。

我被拒绝使用第三个命令的权限,输出如下:

在包含的文件中 /share/apps/boost/1.55​​.0/include/boost/math/special_functions/detail/round_fwd.hpp:11:0, 来自/share/apps/boost/1.55​​.0/include/boost/math/special_functions/math_fwd.hpp:26, 来自/share/apps/boost/1.55​​.0/include/boost/math/special_functions/erf.hpp:13, 来自/share/apps/boost/1.55​​.0/include/boost/math/distributions/normal.hpp:19, 来自 test.cpp:12: /share/apps/boost/1.55​​.0/include/boost/config.hpp:30:29: 致命错误: /share/apps/boost/1.56.0/build/boost_1_56_0/boost/config/user.hpp: 权限被拒绝

我收到第四个命令的错误:

致命错误:boost/math/distributions/normal.hpp:没有这样的文件或 目录。

【问题讨论】:

  • 您应该使用 -L 作为库路径,但您确实需要您可以阅读标题。
  • 看起来我有权阅读它......我不确定问题是什么:/。我尝试直接 #include "/share/apps/boost/1.55​​.0/include/boost/math/..." 但它不起作用,因为它引用了另一个带有 #include
  • 你能在目标机器上自己编译boost并链接到你自己的共享库吗?或者可以复制在您的主工作站上编译的文件?
  • 是的。我最初的计划只是在我的工作站上编译然后在服务器上执行我的程序,但是我收到以下错误:./scrub: error while loading shared libraries: libboost_program_options.so.1.54.0: cannot open shared object file:没有这样的文件或目录但我不确定我是否理解你的第一个问题。对不起,我作为程序员有点缺乏经验。

标签: c++ boost linker


【解决方案1】:

你想用

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 告诉编译器在哪里寻找系统头文件。 -L 告诉链接器在哪里寻找库。如果您需要基于您的代码 sn-p 的 boost 文件系统或系统库,这并不明显。

如果您无法读取远程服务器上的 boost 标头或共享库,这与您的问题无关。请联系您的系统管理员寻求帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多