【问题标题】:undefined references when using Rcpp使用 Rcpp 时未定义的引用
【发布时间】:2016-10-06 23:00:00
【问题描述】:

我正在尝试构建一个 R 包,它是 Windows 中 C 库(并且使用 gsl)的包装器。如有必要,我可以过渡到 Linux 无论好坏,我将 C 库的 make 命令放在 Makevars.in 中。 我使用 Rstudio 的 Rcpp 骨架功能来创建包。我已经安装了 Rtools 3.3 并使用了 R 3.3.1

并且我将 Rcpp 和 RcppGSL 包含在 DESCRIPTION 的 LinkingTo 字段中。我仍然收到 make 命令的未定义参考错误

$(CXX) $(CXXFLAGS)   $(OBJECTS)  ../inst/libgraphm.a $(PKG_LIBS)

一些错误如下

c:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o RGraphM.dll tmp.def graphmatch_rcpp.o RcppExports.o -L../inst -lgraphm -LC:/tools/gsl/lib/x64 -lgsl -lgslcblas -Ld:/Compiler/gcc-4.9.3/local330/lib/x64 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-33~1.1/bin/x64 -lR
#cd graphm && /usr/bin/make
c:/Rtools/mingw_64/bin/g++  -O2 -Wall  -mtune=core2   graphmatch_rcpp.o RcppExports.o  ../inst/libgraphm.a  -L../inst -lgraphm -LC:/tools/gsl/lib/x64 -lgsl -lgslcblas
graphmatch_rcpp.o: In function `PreserveStorage':
C:/Users/sadali/Documents/R/win-library/3.3/Rcpp/include/Rcpp/storage/PreserveStorage.h:10: undefined reference to `__imp_R_NilValue'
graphmatch_rcpp.o: In function `Vector':
C:/Users/sadali/Documents/R/win-library/3.3/Rcpp/include/Rcpp/vector/Vector.h:58: undefined reference to `Rf_allocVector'
graphmatch_rcpp.o: In function `Rcpp_ReplaceObject':

这个类似(在我看来)问题的答案似乎不适用 Undefined reference errors when including Rcpp.h 因为我正在使用 LinkingTo 并尝试创建一个 R 包

编辑:正如第一个答案所建议的那样,我尝试使用以下 Makevars.win 构建 RcppZiggurat:

PKG_CPPFLAGS = -I. -I../inst/include  -IC:/tools/gsl/include 
## Use the R_HOME indirection to support installations of multiple R version
PKG_LIBS = $(LDFLAGS) -L../inst -L$(LIB_GSL)/lib/x64 $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "RcppGSL:::LdFlags()")

我收到这些错误。

ziggurat.o:ziggurat.cpp:(.text+0x86): undefined reference to `gsl_rng_free'

ziggurat.o:ziggurat.cpp:(.text+0xa6): undefined reference to `gsl_rng_free'
ziggurat.o:ziggurat.cpp:(.text+0xc6): undefined reference to `gsl_rng_free'
ziggurat.o:ziggurat.cpp:(.text+0x1254): undefined reference to `gsl_rng_set'

【问题讨论】:

  • graphmatch_rcpp.cpp 的第一个显着行会很有用,但 this 可能是您的问题

标签: r rcpp


【解决方案1】:

我能够使用 Makevars.win 的此模板成功运行 Windows 构建 https://github.com/adalisan/RGraphM/blob/master/src/Makevars.win.gen

这个脚本创建了 Makevars.win https://github.com/adalisan/RGraphM/blob/master/configure.win

一旦将预构建的 gsl windows 库放入 env 定义的目录中。 var LIB_GSL,编译和链接步骤都有效。

一个小问题是预建库downloaded here 的 zip 文件包含两个子架构(i386 和 x64)的两个子目录 您应该确保链接到正确的版本,并且链接器调用中的 -L"$(LIB_GSL)\lib\$(ARCH)" 参数评估到子架构的正确目录。 感谢 Rcpp 和 RcppGSL 的创建者让基于 gsl 的代码的打包变得更加容易。

【讨论】:

    【解决方案2】:

    您对它的工作原理有误解:

    1. DESCRIPTIONLinkingTo: 字段没有链接,尽管它的名称。它只对头文件有帮助。这就是您的包已编译但没有链接的原因。

    2. 您需要链接器指令。如前所述,mvabundRcppZiggurat 包都使用来自RcppGSL 的工具链接到 GSL。

    RcppZiggurat 特别是一个很好的例子,因为它很小。 RcppGSL 中还包含 an entire example package - 我们将其用作参考以及单元测试。

    【讨论】:

    • 我在构建 RcppZiggurat 时也遇到了错误。这是 Makevars.win PKG_CPPFLAGS = -I。 -I../inst/include -IC:/tools/gsl/include ##使用R_HOME间接支持安装多个R版本 PKG_LIBS = $(LDFLAGS) -L../inst -L$(LIB_GSL)/lib /x64 $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "RcppGSL:::LdFlags()")
    • 您可能希望通过查看值的设置方式以及您获得的值来调试它。它适用于 CRAN 的 windows 构建——也许你只是没有设置 GSL 根目录环境变量。
    • 目录对我来说似乎没问题。这是运行的命令: c:/Rtools/mingw_32/bin/g++ -shared -s -static-libgcc -o RcppZiggurat.dll tmp.def RcppExports.o ziggurat.o -L../inst -LC:/工具/gsl/lib/x64 -LC:/tools/gsl/lib -lgsl -lgslcblas -Ld:/Compiler/gcc-4.9.3/local330/lib/i386 -Ld:/Compiler/gcc-4.9.3/local330 /lib -LC:/PROGRA~1/R/R-33~1.1/bin/i386 -lR
    • gsl 库文件位于 C:/tools/gsl/lib/x64 并包含在链接调用中。
    猜你喜欢
    • 1970-01-01
    • 2016-05-09
    • 1970-01-01
    • 2013-06-20
    • 2011-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-05
    相关资源
    最近更新 更多