Re: [Rd] Integration of C and Fortran

From: Hin-Tak Leung <hin-tak.leung_at_cimr.cam.ac.uk>
Date: Wed 05 Apr 2006 - 11:17:14 GMT

Prof Brian Ripley wrote:

> Is
> 

>> the enter point Fortran "orderdata_" absent of the loading table.
> > a manual translation, and was the underscore there in the original (I > think it should be, but am just checking).

The extra underscore added is the default behavior of many fortran compilers, to avoid symbol name collision - I believe this is actually mentioned very briefly in "writing R extensions" - here is the details from the relevant section of the documentation of gfortran (gcc 4.x's fortran front end):



Options for Code Generation Conventions

`-fno-underscoring'

      Do not transform names of entities specified in the Fortran source
      file by appending underscores to them.

      With `-funderscoring' in effect, `gfortran' appends one underscore
      to external names with no underscores.  This is done to ensure
      compatibility with code produced by many UNIX Fortran compilers.

      ....

      Use of `-fno-underscoring' is not recommended unless you are
      experimenting with issues such as integration of (GNU) Fortran into
      existing system environments (vis-a-vis existing libraries, tools,
      and so on).

      ....

`-fsecond-underscore'
      By default, `gfortran' appends an underscore to external names.
      If this option is used `gfortran' appends two underscores to names
      with underscores and one underscore to external names with no
      underscores ...
===================================

> 
> What do nm -g mpackage.so tell you is actually exported from the shared 
> object (here called 'mypackage.so')?  I suspect that will reveal a 
> mismatch of names.
> 
> On Mon, 3 Apr 2006, Sebastien Durand wrote:
> 

>> Dear all,
>>
>> I am running R : Copyright 2005,
>> Version 2.2.1 (2005-12-20 r36812)
>> ISBN 3-900051-07-0
>> On a mac 10.4.5
>>
>> I am having trouble with my package.
>>
>> The trouble is the following:
>>
>> In my package I have integrated three files in my src folder.
>> 1- simplematch.C a .C file
>> 2- ordering.f a fortran file
>> 3- Makevars : PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
>> I am not sure if that last file is really useful!?
>>
>> When I use the R CMD SHLIB command on both these
>> source code files, the resulting compiled .so
>> files when loads fine with the dyn.load function.
>> At last when I use either the
>> .C("simplematch",...) and
>> .Fortran("ordering",...) command everything
>> works...
>>
>> Now here comes trouble:
>>
>> When I do the R CMD INSTALL command, my package install.
>> The .C command works but when I run the .Fortran command I get:
>>
>> Error in .Fortran("orderdata", d = as.double(d),
>> as.integer(n), rowscore = as.double(rowscore)) :
>> the enter point Fortran "orderdata_" absent of the loading table.
>>
>> What should I do to make sure that upon the installation of my package my
>> Fortran function will appear in the load table...
>>
>> Thanks a lot.
>>
>> Sébastien Durand
>>
>> ______________________________________________
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
> 
> 
> ------------------------------------------------------------------------
> 
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed Apr 05 21:32:11 2006

This archive was generated by hypermail 2.1.8 : Wed 05 Apr 2006 - 12:16:52 GMT