Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编译和链接带有cpp代码的R包时的奇怪SHLIB行为_R_Rcpp_R Package - Fatal编程技术网

编译和链接带有cpp代码的R包时的奇怪SHLIB行为

编译和链接带有cpp代码的R包时的奇怪SHLIB行为,r,rcpp,r-package,R,Rcpp,R Package,我正在编译一个R包,其中包含来自第三方的.cpp源文件。要将.cpp文件编译到静态库中,我使用Makevars.win文件()。我在试图修复另一个与parallelmake相关的问题时,偶然发现了仅在Windows上使用SHLIB的一个奇怪行为,该问题表明我在Makevars和Makevars.win文件()中将$(SHLIB)定义为($SHLIB) 长话短说,我在Makevars和Makevars.win文件中错误地将$(SHLIB)写成($SHILB)。在Linux和OSX计算机上纠正该错误

我正在编译一个R包,其中包含来自第三方的
.cpp
源文件。要将
.cpp
文件编译到静态库中,我使用
Makevars.win
文件()。我在试图修复另一个与parallel
make
相关的问题时,偶然发现了仅在Windows上使用
SHLIB
的一个奇怪行为,该问题表明我在
Makevars
Makevars.win
文件()中将
$(SHLIB)
定义为
($SHLIB)

长话短说,我在
Makevars
Makevars.win
文件中错误地将
$(SHLIB)
写成
($SHILB)
。在
Linux
OSX
计算机上纠正该错误不会给我带来任何错误,但在Windows上
($SHLIB)
可以工作,但
$(SHLIB)
会给我以下错误:

C:\Rtools\mingw_64\bin\nm.exe: cvode_bandpre_impl.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: cvode_bbdpre_impl.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: cvode_diag_impl.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: cvode_direct_impl.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: cvode_impl.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: cvode_spils_impl.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: cvode.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: cvode_bandpre.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: cvode_bbdpre.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: cvode_diag.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: cvode_direct.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: cvode_impl.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: cvode_spils.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: fnvector_serial.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: nvector_serial.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_band.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_config.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_dense.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_direct.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_fconfig.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_fnvector.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_iterative.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_linearsolver.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_math.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_matrix.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_nvector.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_pcg.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_sparse.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_spbcgs.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_spfgmr.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_spgmr.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_sptfqmr.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_types.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sundials_version.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: fsunlinsol_dense.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sunlinsol_band.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sunlinsol_dense.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sunlinsol_pcg.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sunlinsol_spbcgs.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sunlinsol_spfgmr.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sunlinsol_spgmr.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sunlinsol_sptfqmr.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: fsunmatrix_dense.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: fsunmatrix_band.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sunmatrix_band.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sunmatrix_dense.h: File format not recognized
C:\Rtools\mingw_64\bin\nm.exe: sunmatrix_sparse.h: File format not recognized
c:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o sundialr.dll tmp.def cvode.o RcppExports.o -LC:/PROGRA~1/R/R-34~1.1/bin/x64 -lRlapack -LC:/PROGRA~1/R/R-34~1.1/bin/x64 -lRblas -lgfortran -lm -lquadmath -L../inst/ -lsundials_all -Ld:/Compiler/gcc-4.9.3/local330/lib/x64 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-34~1.1/bin/x64 -lR
../inst//libsundials_all.a(cvode_bandpre.o):cvode_bandpre.c:(.text+0x679): undefined reference to `SUNBandLinearSolver'
../inst//libsundials_all.a(cvode_bandpre.o):cvode_bandpre.c:(.text+0x360): undefined reference to `SUNLinSolSetup_Band'
../inst//libsundials_all.a(cvode_bbdpre.o):cvode_bbdpre.c:(.text+0x819): undefined reference to `SUNBandLinearSolver'
../inst//libsundials_all.a(cvode_bbdpre.o):cvode_bbdpre.c:(.text+0x2ea): undefined reference to `SUNLinSolSetup_Band'
collect2.exe: error: ld returned 1 exit status
no DLL was created
ERROR: compilation failed for package 'sundialr'
我理解
未定义引用
错误消息是链接错误,但我不确定为什么会收到头文件的
文件格式未识别
错误消息。更有趣的是,当WRE文档谈到
$(SHLIB)
而不是
($SHLIB)
时,为什么在
Makevars.win
文件中用
$(SHLIB)
替换
$(SHLIB)
一切都很好。事实上,该包通过了所有的CRAN检查,并且直到最近才在
Makevars.win
中使用
($SHLIB)


有人能解释为什么会发生这种情况,以及我如何解决现在使用
$(SHLIB)
时遇到的错误吗。我想替换代码中错误的
($SHLIB)
。谢谢

您的
源*
变量混合了
.c
.h
文件。
对象的
.c
将替换为
对象的
.o
,而
.h
文件将保留在中。在构建静态库时,这些似乎会混淆
nm.exe
。如果从
源代码*
变量中删除
.h
文件,则
无法识别的文件格式
消息应该会消失。

非常感谢Ralf!实际上,删除头文件可以消除这些错误。我还能够通过在
/src
子文件夹中包含一个我以前丢失的源文件来解决链接错误。你真是帮了大忙!对于阅读本文的其他人-我仍然不明白为什么它与
($SHLIB)
一起工作,所以任何解释都将不胜感激!