build R package with C code (without Rcpp)

亡梦爱人 提交于 2021-01-28 05:07:31

问题


environment:

  • OS:Windows10 [10.0.14393]
  • R:3.4.1 (2017-06-30) -- "Single Candle" 32-bit
  • Rstudio:1.0.143
  • Rtools:3.4.0.1964

This is my first time to build R package (named testt).
I'm trying to build a package with some C code without using Rcpp.
I have put all .c files (called lca.c, rlca_cond.c, rlca_prev.cand rlca_condprev.c)
and their header file in /src.

And I have some C function defined in chanmat.c, declared in chanmat.h.
chanmat.c and chanmat.h are also in /src.
Both lca.h, rlca_cond.h, rlca_prev.h and rlca_condprev.h have #include 'chanmat.h'.

In chanmat.h, I use the following to prevent multiple definition when compiling.

#ifndef CHANMATH_H
#define CHANMATH_H
...
#endif

I have also used following in NAMESPACE file (generated by roxygen2)

useDynLib(testt,lca)
useDynLib(testt,rlca_cond)
useDynLib(testt,rlca_prev)
useDynLib(testt,rlca_condprev)
useDynLib(testt,chanmat)

When I run build & reload, I got following error

Updating testt documentation
Loading testt
Error in FUN(X[[i]], ...) : 
  no such symbol chanmat in package 
C:/Users/elephant/Desktop/project/testt/src/testt.dll
Calls: suppressPackageStartupMessages ... assignNativeRoutines -> 
getNativeSymbolInfo -> lapply -> FUN
��������

Exited with status 1.

I have no idea why chanmat.c/chanmat.h are failed to compile.
This question bothers me for a long time.
Any thoughts on how to fix this?

来源:https://stackoverflow.com/questions/45541684/build-r-package-with-c-code-without-rcpp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!