简体   繁体   English

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

[英]Odd SHLIB behavior while compiling and linking an R package with cpp code

I am compiling an R package containing .cpp source files from a third party. 我正在编译一个包含来自第三方的.cpp源文件的R包。 To compile the .cpp files into a static library, I am using the Makevars.win file ( link ). 要将.cpp文件编译为静态库,我使用的是Makevars.win文件( 链接 )。 I stumbled upon an odd behavior of SHLIB on Windows only, while trying to fix another problem related to parallel make which revealed that I had a misplaced parenthesis defining $(SHLIB) as ($SHLIB) in Makevars and Makevars.win files ( link ). 我偶然发现了SHLIB在Windows上的一个奇怪的行为,同时试图解决另一个与并行make相关的问题,这个问题显示我在MakevarsMakevars.win文件中有一个错误的括号,将$(SHLIB)定义为($SHLIB)链接 ) 。

Long story short, I had written $(SHLIB) incorrectly as ($SHILB) in my Makevars and Makevars.win files. 长话短说,我在MakevarsMakevars.win文件($SHILB) $(SHLIB)错误地写为($SHILB) Correcting that mistake gives me no error on Linux and OSX machines, but on Windows ($SHLIB) works, but $(SHLIB) gives me the following error: 纠正错误在LinuxOSX机器上没有错误,但在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'

I understand the undefined reference error messages are linking errors, but I am not sure why I am getting the File format not recognized error messages for header files. 我理解undefined reference错误消息是链接错误,但我不知道为什么我得到File format not recognized头文件的错误消息。 More interestingly, why it all works fine with substituting $(SHLIB) with ($SHLIB) in the Makevars.win file when the WRE document talks about $(SHLIB) and not ($SHLIB) . 更有趣的是,为什么这一切工作正常与代$(SHLIB)($SHLIB)Makevars.win当WRE文档谈论文件$(SHLIB)而不是($SHLIB) In fact, the package passed all CRAN checks and was on CRAN till very recently with ($SHLIB) in Makevars.win . 事实上,该软件包通过了所有CRAN检查,直​​到最近才在Makevars.win使用($SHLIB)

Can any one explain why this is happening and how can I resolve the errors I am getting with $(SHLIB) now. 任何人都可以解释为什么会这样,我现在如何解决我用$(SHLIB)得到的错误。 I would like to replace the erroneous ($SHLIB) in my code. 我想在我的代码中替换错误的($SHLIB) Thanks! 谢谢!

Your SOURCES_* variables have a mixture of .c and .h files. 您的SOURCES_*变量包含.c.h文件的混合。 The .c are replaces with .o for OBJECTS_SUNDIALS_ALL , but the .h files stay in. These seem to confuse nm.exe when building the static library. 对于OBJECTS_SUNDIALS_ALL.c替换为.o ,但.h文件保留。这些似乎在构建静态库时会混淆nm.exe If you remove the .h files from the SOURCES_* variables, the File format not recognized messages should go away. 如果从SOURCES_*变量中删除.h文件,则File format not recognized消息应该消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM