从 R 调用 C++ 程序时不会 运行(符号查找错误)

C++ Program Won't Run When Invoked From R (Symbol Lookup Error)

我有一个 c++ 程序 Alpine3d,当我从命令行调用它时 运行 没问题。该程序使用 MongoCXX 将数据输出到 MongoDB。

在一台 Ubuntu 18 PC 上,我可以使用 "system" 命令从 R 成功 运行 Alpine3d。但是,在另一台 Ubuntu 18 台 PC 上,Alpine3D 运行s 从命令行正确运行,尝试从 R 运行 Alpine3D 抛出错误:

alpine3d: symbol lookup error: /usr/local/lib/libmongocxx.so._noabi: undefined symbol: mongoc_transaction_opts_destroy

此库 /usr/local/lib/libmongocxx.so._noabi 存在。我怀疑可能是 MongoCXX 安装不当,但重新安装后我认为不是。

基于此线程,Error while loading shared libraries: libbsoncxx.so._noabi: cannot open shared object file: No such file or directory,我还使用了 CMakeLists.txt 来确保 Mongo 和 BSON 库正确链接并且看起来它们是捡到成功。

有什么要调查的想法吗?如果有人知道从哪里开始,很高兴展示一些代码。

感谢任何想法!

[更新] 回应 Ralf 的评论:

命令行ldd $(which alpine3d)的输出为:

$ ldd $(which alpine3d)
    linux-vdso.so.1 (0x00007ffc097aa000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f15a5675000)
    libbsoncxx.so._noabi => /usr/local/lib/libbsoncxx.so._noabi (0x00007f15a5458000)
    libmongocxx.so._noabi => /usr/local/lib/libmongocxx.so._noabi (0x00007f15a51cb000)
    libalpine3d.so.3 => /usr/local/lib/libalpine3d.so.3 (0x00007f15a4f39000)
    libmeteoio.so.2 => /usr/local/lib/libmeteoio.so.2 (0x00007f15a4b0f000)
    libsnowpack.so.3 => /usr/local/lib/libsnowpack.so.3 (0x00007f15a480a000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f15a4481000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f15a40e3000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f15a3ecb000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f15a5c7f000)
    libbson-1.0.so.0 => /usr/local/lib/libbson-1.0.so.0 (0x00007f15a3c91000)
    libmongoc-1.0.so.0 => /usr/local/lib/libmongoc-1.0.so.0 (0x00007f15a3a06000)
    libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f15a37d7000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f15a35b8000)
    libproj.so.12 => /usr/lib/x86_64-linux-gnu/libproj.so.12 (0x00007f15a334f000)
    liblapack.so.3 => /usr/lib/x86_64-linux-gnu/liblapack.so.3 (0x00007f15a2ac9000)
    libblas.so.3 => /usr/lib/x86_64-linux-gnu/libblas.so.3 (0x00007f15a286e000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f15a2666000)
    libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f15a244b000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f15a222e000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f15a202a000)
    libopenblas.so.0 => /usr/lib/x86_64-linux-gnu/libopenblas.so.0 (0x00007f159fd84000)
    libgfortran.so.4 => /usr/lib/x86_64-linux-gnu/libgfortran.so.4 (0x00007f159f9a5000)
    libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f159f765000)

其中显示了指向 libmongocxx 等的链接

来自 R:

system("ldd $(which alpine3d)")
    linux-vdso.so.1 (0x00007ffe0d5f2000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1fa84e4000)
    libbsoncxx.so._noabi => /usr/local/lib/libbsoncxx.so._noabi (0x00007f1fa82c7000)
    libmongocxx.so._noabi => /usr/local/lib/libmongocxx.so._noabi (0x00007f1fa803a000)
    libalpine3d.so.3 => /usr/local/lib/libalpine3d.so.3 (0x00007f1fa7da8000)
    libmeteoio.so.2 => /usr/local/lib/libmeteoio.so.2 (0x00007f1fa797e000)
    libsnowpack.so.3 => /usr/local/lib/libsnowpack.so.3 (0x00007f1fa7679000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f1fa72f0000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f1fa6f52000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f1fa6d3a000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f1fa8aee000)
    libbson-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libbson-1.0.so.0 (0x00007f1fa6b03000)
    libmongoc-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libmongoc-1.0.so.0 (0x00007f1fa6890000)
    libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f1fa6661000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f1fa6442000)
    libproj.so.12 => /usr/lib/x86_64-linux-gnu/libproj.so.12 (0x00007f1fa61d9000)
    liblapack.so.3 => /usr/lib/x86_64-linux-gnu/liblapack.so.3 (0x00007f1fa5953000)
    libblas.so.3 => /usr/lib/x86_64-linux-gnu/libblas.so.3 (0x00007f1fa56f8000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f1fa54f0000)
    libssl.so.1.1 => /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007f1fa5263000)
    libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f1fa4d98000)
    libsnappy.so.1 => /usr/lib/x86_64-linux-gnu/libsnappy.so.1 (0x00007f1fa4b90000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f1fa4973000)
    libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f1fa4758000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f1fa4554000)
    libopenblas.so.0 => /usr/lib/x86_64-linux-gnu/libopenblas.so.0 (0x00007f1fa22ae000)
    libgfortran.so.4 => /usr/lib/x86_64-linux-gnu/libgfortran.so.4 (0x00007f1fa1ecf000)
    libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f1fa1c8f000)

我现在可以看到文件夹不同了。 R从哪里得到这个变量是不同的?再次感谢!

感谢 Ralf 的评论,我明白了这一点。我必须从命令行和从源代码构建来安装 libmongoc。要卸载 /usr/lib/x86_64-linux-gnu 中的版本,我只是使用了命令行:

sudo apt-get remove libmongoc-1.0-0