[Bioc-devel] Register native routines

Martin Morgan martin.morgan at roswellpark.org
Tue Mar 15 17:37:45 CET 2016



On 03/15/2016 12:30 PM, Aaron Taudt wrote:
> I know they were not registered because BiocCheck told me so. In
> addition, getDLLRegisteredRoutines('AneuFinder') returned an empty
> data.frame.
>
> But wrapping the R_init_<pkg> in an extern "C" block solved the problem:
> extern "C" {
> void R_init_AneuFinder(DllInfo *dll)
> {
>      R_registerRoutines(dll, CEntries, NULL, NULL, NULL);
>      R_useDynamicSymbols(dll, FALSE);
> //     R_forceSymbols(dll, TRUE);
> }
> }
>
> Thanks!
>
> I am not sure what causes the nan_detected problem and I cannot
> reproduce it ... Any advice?

This requires that the optimization flag be set to level 0, which can be 
done by editing R.home("etc/Makeconf") to have a line like

     CXXFLAGS = -O0

I *think* this reproduces across g++ and clang...

The problem is I think with the 'extern' keyword. With optimizations, 
the pre-processor inlines the definition, so there is never a symbol 
nan_detected. Without optimization the 'extern' keyword is taken 
literally to mean that the symbol is defined elsewhere; since there is 
no actual definition, it remains undefined. [probably playing a little 
loose with what is actually going on...]. One solution is to provide an 
actual (non-extern) definition, e.g., in a .cpp file. The high-scoring 
answer here 
http://stackoverflow.com/questions/11055802/static-and-extern-global-variables-in-c-and-c 
might provide a starting point for more rigorous understanding / solution.

Martin

>
> /Dipl. Biol. (t.o.) Aaron Taudt | PhD Student | University Medical
> Center Groningen
> European Research Institute for the Biology of Ageing (ERIBA)|
> Quantitative Epigenetics
> ///
> /A. Deusinglaan 1, gebouw 3226 | 9700 AD Groningen. |
> //_www.ERIBA.umcg.nl_/
> <https://mail.umcg.nl/owa/redir.aspx?SURL=MjFlzpaBN8LXiiXqvA10ICpS6i9DfAZ16RduD6U39IiuC_t5NUTTCGgAdAB0AHAAcwA6AC8ALwBtAGEAaQBsAC4AdQBtAGMAZwAuAG4AbAAvAG8AdwBhAC8AVQByAGwAQgBsAG8AYwBrAGUAZABFAHIAcgBvAHIALgBhAHMAcAB4AA..&URL=https%3a%2f%2fmail.umcg.nl%2fowa%2fUrlBlockedError.aspx>
>
> 2016-03-15 14:09 GMT+01:00 Martin Morgan <martin.morgan at roswellpark.org
> <mailto:martin.morgan at roswellpark.org>>:
>
>     Hi Aaron --
>
>
>     On 03/15/2016 08:40 AM, Aaron Taudt wrote:
>
>         I am trying to register my native routines as recommended by
>         BiocCheck. I
>         followed the instructions in "Writing R Extensions" and have
>         implemented
>         the following code in "init.cpp". However, the routines are
>         still not
>         registered.
>
>         #include <Rinternals.h>
>         #include <R_ext/Rdynload.h>
>         #include "R_interface.h"  // contains univariate_hmm,
>         multivariate_hmm, etc.
>
>         static const R_CMethodDef CEntries[]  = {
>               {"univariate_hmm", (DL_FUNC) &univariate_hmm, 24,
>         (R_NativePrimitiveArgType[24]) {INTSXP, INTSXP, INTSXP, INTSXP,
>         REALSXP,
>         REALSXP, INTSXP, INTSXP, REALSXP, INTSXP, REALSXP, REALSXP, REALSXP,
>         REALSXP, INTSXP, REALSXP, REALSXP, REALSXP, REALSXP, LGLSXP, INTSXP,
>         INTSXP, INTSXP, INTSXP}},
>               {"multivariate_hmm", (DL_FUNC) &multivariate_hmm, 18,
>         (R_NativePrimitiveArgType[18]) {REALSXP, INTSXP, INTSXP, INTSXP,
>         INTSXP,
>         INTSXP, INTSXP, REALSXP, INTSXP, REALSXP, REALSXP, REALSXP, REALSXP,
>         REALSXP, LGLSXP, INTSXP, INTSXP, INTSXP}},
>               {"univariate_cleanup", (DL_FUNC) &univariate_cleanup, 0,
>         NULL},
>               {"multivariate_cleanup", (DL_FUNC) &multivariate_cleanup, 1,
>         (R_NativePrimitiveArgType[1]) {INTSXP}},
>               {NULL, NULL, 0, NULL}
>         };
>
>         void R_init_AneuFinder(DllInfo *dll)
>         {
>               R_registerRoutines(dll, CEntries, NULL, NULL, NULL);
>               R_useDynamicSymbols(dll, FALSE);
>         }
>
>         My NAMESPACE contains
>         useDynLib(AneuFinder, .registration = TRUE)
>
>         I don't see what's missing here, because the routines are still not
>         registered. I appreciate any help.
>
>
>     How do you know that they are not registered?
>
>     This is C code, but init.cpp is compiled by the C++ compiler; do you
>     need extern "C" {} around the this code?
>
>     When I try to install the most recent version of your package on the
>     tracker, my default setting has compiler option -O0 (in
>     R.home("etc/Makeconf")) and the nan_expected symbol is missing from
>     the shared object
>
>     ** testing if installed package can be loaded
>     Bioconductor version 3.3 (BiocInstaller 1.21.3), ?biocLite for help
>     Error in dyn.load(file, DLLpath = DLLpath, ...) :
>        unable to load shared object
>     '/home/mtmorgan/R/x86_64-pc-linux-gnu-library/3.3/AneuFinder/libs/AneuFinder.so':
>
>     /home/mtmorgan/R/x86_64-pc-linux-gnu-library/3.3/AneuFinder/libs/AneuFinder.so:
>     undefined symbol: nan_detected
>     Error: loading failed
>     Execution halted
>     ERROR: loading failed
>
>
>     Martin
>
>
>                  [[alternative HTML version deleted]]
>
>         _______________________________________________
>         Bioc-devel at r-project.org <mailto:Bioc-devel at r-project.org>
>         mailing list
>         https://stat.ethz.ch/mailman/listinfo/bioc-devel
>
>
>
>     This email message may contain legally privileged and/or
>     confidential information.  If you are not the intended recipient(s),
>     or the employee or agent responsible for the delivery of this
>     message to the intended recipient(s), you are hereby notified that
>     any disclosure, copying, distribution, or use of this email message
>     is prohibited.  If you have received this message in error, please
>     notify the sender immediately by e-mail and delete this email
>     message from your computer. Thank you.
>
>


This email message may contain legally privileged and/or confidential information.  If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited.  If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you.



More information about the Bioc-devel mailing list