[R] R CMD SHLIB: file not recognized: File format not recognized

Prof Brian Ripley ripley at stats.ox.ac.uk
Sun Oct 19 09:54:08 CEST 2008


>From the help page:

    'R CMD SHLIB' is the mechanism used by 'INSTALL' to compile source
    code in packages. Please consult section 'Creating shared objects'
    in the manual 'Writing R Extensions' for how to customize it (for
    example to add 'cpp' flags and to add libraries to the link step)
    and for details of some of its quirks.
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

and from that reference

   Note that as R CMD SHLIB uses Make, it will not remake a shared object
   just because the flags have changed, and if test.c and test.f both exist
   in the current directory

      R CMD SHLIB test.f

   will compile test.c!

In your case the target systen has changed, but that's not enough to force
recompilation of the .c file.


On Sun, 19 Oct 2008, Andreas Wittmann wrote:

> Hello Dirk,
>
> thank you for your chick answer.
> I tried another file and there it works. so i removed all files
> which were created during of the compilation of add.c in windows
> and so i could compile it under ubuntu too. During the windows
> compilation there is some *.o file which is created during the
> compilation, if i delete it and try the compilation under ubuntu
> everything works fine, don't know why?
>
> best regards
>
> Andreas
>
>
>
>
> Dirk Eddelbuettel wrote:
>> On Sun, Oct 19, 2008 at 01:27:06AM +0200, Andreas Wittmann wrote:
>>
>>> Dear R useRs,
>>>
>>> on ubuntu 8.04 i try to create a shared object out of a c-file
>>> this is
>>>
>>> // add.c
>>>
>>> #include <Rinternals.h>
>>> SEXP addiere(SEXP a, SEXP b)
>>> {
>>>  int i, n;
>>>  n = length(a);
>>>  for (i = 0; i < n; i++)
>>>    REAL(a)[i] += REAL(b)[i];
>>>  return(a);
>>> }
>>>
>>> in terminal i type
>>>
>>> R CMD SHLIB add.c
>>>
>>> and get
>>>
>>> gcc -std=gnu99 -shared  -o add.so add.o   -L/usr/lib/R/lib -lR
>>> add.o: file not recognized: File format not recognized
>>>
>>> my gcc version is 4.2.3 and my R version is 2.7.2.
>>>
>>
>> I can't replicate that on Ubuntu 8.04:
>>
>> edd at joe:/tmp$ R CMD SHLIB add.c
>> gcc -std=gnu99 -I/usr/share/R/include      -fpic  -g -O2 -c add.c -o add.o
>> gcc -std=gnu99 -shared  -o add.so add.o   -L/usr/lib/R/lib -lR
>> edd at joe:/tmp$
>>
>> Works fine here. Have you compiled other files?  Or are you maybe
>> missing some -dev packages?
>>
>> Dirk
>>
>>
>>> Searching R-help, Writing R Extensions and R Installation and
>>> Administration guide
>>> i don't get any idea whats wrong here?
>>>
>>> Creating a dll-file on windows xp with the same c-file works fine.
>>>
>>> best regards
>>>
>>> Andreas
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list