我在Windows上運行使用Rcpp構建的函數時遇到了調用問題,如果我的C++代碼使用C++ 11 std::regex
,並且我目前找不到出路。Rcpp C++ 11. Windows下的呼叫問題
與以往有關類似問題的問題不同,我既沒有構建也沒有鏈接問題。 Rcpp包使用C++ 11插件進行構建和鏈接,在我的平臺上製作可用包。當不使用std::regex
時,constexpr
和C++ 11特定功能(如std::stoi
)不會導致問題。
使用Windows升級庫,即使指定了PKG_LIBS =「 - L/path/to/boost/libs -lboost_regex」,我也遇到鏈接問題,所以我寧願堅持std::regex
。
相同的包在linux下使用vanilla std :: regex或boost :: regex構建,安裝並運行良好。
我不幸在Rcpp畫廊的例子中找不到解決方案。
Windows平臺是:
Windows >= 8 x64 (build 9200)
Rcpp_0.12.3
Rtools 3.3.0.1959 running g++ 4.9.3 (x86_64-posix-seh,
built by MinGW-W64 project), normally C++11-compatible.
PKG_CXXFLAGS="-std=c++11"
Linux平臺是除了克類似++(5.3版):
R version 3.2.3 (2015-12-10)
x86_64-w64-mingw32/x64 (64-bit)
下運行。
以下是複製的簡化代碼塊。
#include <Rcpp.h>
#if defined(__linux__) && ! defined(FORCE_STL_BUILD)
#include <boost/regex.hpp>
#define reglib boost
#else
#include <regex>
#define reglib std
#endif
#include <string>
using namespace Rcpp;
// [[Rcpp::plugins(cpp11)]]
constexpr int a[3]= {2, 10, 15};
// [[Rcpp::export]]
int my_test(int prop, const std::string& index)
{
#ifndef NO_REG
static const reglib::regex test {"H.*A", reglib::regex::icase};
#endif
int index_int = std::stoi(index) + a[1] + prop;
return index_int;
}
使用-DNO_REG構建時,此代碼運行正常。否則調用test::my_test(1, "1000")
回報:
`Error in .Call("test_my_test", PACKAGE = "test", prop, index) :
"test_my_test" not available for .Call() for package "test"`
編輯:
1.問題的重點的std ::正則表達式。提升問題只是偶然的評論。
2.問題包裝後只出現時,不使用Rcpp::source("cppfile")
3.包裝代碼:
ř控制檯:
Rcpp::Rcpp.package.skeleton("test", attributes=TRUE, example_code=FALSE, cpp_files="test.cpp")
Rcpp::compileAttributes("test")
CMD控制檯:
REM paths to R/bin/x64 and Rtools/bin, Rtools/mingw_64/bin added to PATH
set PKG_CXXFLAGS=-std=c++11
R CMD build test
R CMD INSTALL test_1.0.tar.gz
附加編輯:
.CALL問題只要在C++代碼中聲明正則表達式就會出現。使用它或不使用(如在std :: regex_match中)不會改變。
簡而言之:a)使用sourceCpp(「test.cpp」)不會出現上述問題。所以是的,這實際上不是一個Rcpp問題,而是一個Rcpp相關的包裝障礙。 b)我對你的評論感到驚訝,g ++ 4.9.3 for R還沒有發佈:vanilla RTools 3.3 Windows包帶有g ++ 4.9.3,沒有其他東西。 c)自從std :: regex被納入標準之後,使用它已經是普通的C++ 11編程。所以我不認爲我正在將Rcpp推到非標準代碼的角落 - 只是寫簡單的現代C++。 – Fab
你能詳細介紹一下假設的「障礙」,然後可能提交一張問題單嗎?至於Rtools,請參閱[這裏](https://cran.r-project.org/bin/windows/Rtools/) - 這是一個'內棒球',但'冰凍:否'意味着最終確定。尚未用於R版本。但測試它是一個好主意。 –
在github上提交的發行票有點縮小。 – Fab