From dutangc at gmail.com  Wed May 10 10:56:46 2017
From: dutangc at gmail.com (Christophe Dutang)
Date: Wed, 10 May 2017 10:56:46 +0200
Subject: [Rd] registering Fortran routines in R packages
In-Reply-To: <1494399417326.77831@oulu.fi>
References: <1CDAFD25-E227-42EA-A689-87B3036434AB@gmail.com>
 <93D3A75D-290F-49B3-9E37-FD88F78E2BEF@xs4all.nl>
 <1072BC5F-750D-4DF8-8B7B-7D8E665EDE00@gmail.com>
 <696AFC2F-DD3D-4E5E-BC4E-12B87087CA6F@xs4all.nl>
 <1494399417326.77831@oulu.fi>
Message-ID: <736AE6CB-6F64-4562-BA5C-2B2E1322D9D0@gmail.com>

Thanks Jari and Berend.

I was not aware of that function. I do use it : indeed it may extern declarations for Fortran routines. see https://r-forge.r-project.org/scm/viewvc.php/pkg/randtoolbox/src/init.c?view=markup&root=rmetrics <https://r-forge.r-project.org/scm/viewvc.php/pkg/randtoolbox/src/init.c?view=markup&root=rmetrics>

However I get a new error when building 

Error: package or namespace load failed for ?randtoolbox? in dyn.load(file, DLLpath = DLLpath, ...):
 impossible de charger l'objet partag? '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/randtoolbox/libs/randtoolbox.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/randtoolbox/libs/randtoolbox.so, 6): Symbol not found: _halton_f_
  Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/randtoolbox/libs/randtoolbox.so
  Expected in: flat namespace
 in /Library/Frameworks/R.framework/Versions/3.4/Resources/library/randtoolbox/libs/randtoolbox.so
Erreur : le chargement a ?chou?
Ex?cution arr?t?e
ERROR: loading failed

Note that I change the name of Fortran routines to halton_f and sobol_f to avoid conflict with C version also renamed halton_c and sobol_c.

In the NAMESPACE, I put at the top useDynLib(randtoolbox, .registration = TRUE). 

Berend, I do look at your package? I still don?t figure out why it works for you!

Regards, Christophe

---------------------------------------
Christophe Dutang
LMM, UdM, Le Mans, France
web: http://dutangc.free.fr <http://dutangc.free.fr/>
> Le 10 mai 2017 ? 08:56, Jari Oksanen <jari.oksanen at oulu.fi> a ?crit :
> 
> Have you tried using tools:::package_native_routine_registration_skeleton()? If you don't like its output, you can easily edit its results and still avoid most pitfalls.
> 
> Cheers, Jari Oksanen
> ________________________________________
> From: R-devel <r-devel-bounces at r-project.org> on behalf of Berend Hasselman <bhh at xs4all.nl>
> Sent: 10 May 2017 09:48
> To: Christophe Dutang
> Cc: r-devel at r-project.org
> Subject: Re: [Rd] registering Fortran routines in R packages
> 
> Christophe,
> 
>> On 10 May 2017, at 08:08, Christophe Dutang <dutangc at gmail.com> wrote:
>> 
>> Thanks for your email.
>> 
>> I try to change the name in lowercase but it conflicts with a C implementation also named halton. So I rename the C function halton2() and sobol2() while the Fortran function are HALTON() and SOBOL() (I also try lower case in the Fortran code). Unfortunately, it does not help since I get
>> 
>> init.c:97:25: error: use of undeclared identifier 'halton_'; did you mean 'halton2'?
>>  {"halton", (DL_FUNC) &F77_SUB(halton),  7},
>> 
>> My current solution is to comment FortEntries array and use R_useDynamicSymbols(dll, TRUE) for a dynamic search of Fortran routines.
> 
> Have a look at my package geigen and its init.c.
> Could it be that you are missing extern declarations for the Fortran routines?
> 
> 
> Berend
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


	[[alternative HTML version deleted]]



[Rd] registering Fortran routines in R packages
Christophe Dutang