我和libctor一起在Rcpp上有一个非常奇怪的行为。
我有一个具有2个功能的文件:
#include <torch/torch.h>
#include <Rcpp.h>
// [[Rcpp::export]]
void test_error () {
throw std::runtime_error("hi this is my error");
}
// [[Rcpp::export]]
void test_error2 () {
Rcpp::Rcout << torch::arange(1) << std::endl;
}
当我打电话时test_error()
出现段错误(g ++):
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted (core dumped)
clang ++错误是:
terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_M_create
Aborted (core dumped)
test_error2
可以正常工作。
此错误仅在Ubuntu Xenial上发生。我使用Ubuntu Trusty和MacOS进行了测试,没有出现段错误。
如果我test_error2
从文件中删除的代码,即使没有删除该#include <torch/torch.h>
行也没有任何错误。
还测试了使用clang ++和g ++进行编译。同样的错误。
有谁知道这可能是什么?
注意configure文件将从pytorch的网站上自动下载并安装libtorch。因此,如果您不想这样做,请不要安装软件包。
事实证明,使用较旧版本编译程序包g++
效果很好。
我安装了g++-4.9
:
sudo apt-get install g++-4.9
。
编辑.R/Makevars
使用g++-4.9
:
CXX=g++-4.9
CXX11=g++-4.9
然后重新编译Rcpp和程序包。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句