我正在尝试将 R CMD SHLIB 用于使用 Lapack 和 Blas 编写的 C 程序。我在 Windows 中使用命令提示符。但它似乎无法链接到外部库。如何链接这些库?
D:\R\testR>Rcmd SHLIB fmpc.c
c:/Rtools/mingw_64/bin/gcc -shared -s -static-libgcc -o fmpc.dll tmp.def fmpc.o
-Ld:/Compiler/gcc-4.9.3/local330/lib/x64 -Ld:/Compiler/gcc-4.9.3/local330/lib -L
D:/R/R-3.3.2/bin/x64 -lR
fmpc.o:fmpc.c:(.text+0x76d): undefined reference to `dposv_'
fmpc.o:fmpc.c:(.text+0x800): undefined reference to `dtrtrs_'
fmpc.o:fmpc.c:(.text+0x83b): undefined reference to `dtrtrs_'
fmpc.o:fmpc.c:(.text+0x92f): undefined reference to `dposv_'
fmpc.o:fmpc.c:(.text+0x9bf): undefined reference to `dtrtrs_'
fmpc.o:fmpc.c:(.text+0x9fa): undefined reference to `dtrtrs_'
fmpc.o:fmpc.c:(.text+0xb19): undefined reference to `dgemm_'
最佳答案
您有一个链接器 错误,而不是编译器 错误。编译步骤顺利通过。
解决方案:告诉 R 链接到丢失的库,大多数方法是添加一个包含以下内容的文件 src/Makevars.win
:
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
它是使用 R 知道的其他变量的变量声明。
关于c - R CMD SHLIB 编译 C 代码时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42118561/