pleydell at supagro.inra.fr
2009-Sep-15 18:04 UTC
[Rd] Building R package with .c sub-routine files
Lets say I have two source files file1.c and file2.c The latter just contains sub-routines to be used by the first. i.e. in file1.c I have the line #include "file2.c" Let's say "R CMD SHLIB file1.c" runs perfectly and I want to include the code in a package, "R CMD build" also runs fine but R CMD check" gives * checking whether package 'myPackage' can be installed ... ERROR Installation failed. See '/pathto/myPackage.Rcheck/00install.out' for details. basically the compiler is trying to compile file2.c independantly of file1.c which is not what I want and prevents a proper build What's the easiest way to enforce the correct file dependencies when building R packages? cheers David
On 9/15/2009 2:04 PM, pleydell at supagro.inra.fr wrote:> Lets say I have two source files file1.c and file2.c > > The latter just contains sub-routines to be used by the first. i.e. in file1.c I > have the line > > #include "file2.c"That's not the normal way to program in C: normally you'd have a separate file2.h header file which is all you'd include in file1.c, and compile file2.c using the same header file to a separate object file. I guess you could probably get your scheme to work by renaming file2.c to file2.h, but putting actual executable code into a .h file seems pretty strange. Duncan Murdoch> > > Let's say "R CMD SHLIB file1.c" runs perfectly and I want to include the code in > a package, "R CMD build" also runs fine but R CMD check" gives > > * checking whether package 'myPackage' can be installed ... ERROR > Installation failed. > See '/pathto/myPackage.Rcheck/00install.out' for details. > > basically the compiler is trying to compile file2.c independantly of file1.c > which is not what I want and prevents a proper build > > What's the easiest way to enforce the correct file dependencies when building R > packages? > > cheers > David > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Create a file named Makevars in the same directory and put the following line in it: OBJECTS=file1.o Then R CMD SHLIB will only compile file1.c. Kjell On Sep 15, 2009, at 8:04 PM, pleydell at supagro.inra.fr wrote:> Lets say I have two source files file1.c and file2.c > > The latter just contains sub-routines to be used by the first. i.e. > in file1.c I > have the line > > #include "file2.c" > > > Let's say "R CMD SHLIB file1.c" runs perfectly and I want to > include the code in > a package, "R CMD build" also runs fine but R CMD check" gives > > * checking whether package 'myPackage' can be installed ... ERROR > Installation failed. > See '/pathto/myPackage.Rcheck/00install.out' for details. > > basically the compiler is trying to compile file2.c independantly > of file1.c > which is not what I want and prevents a proper build > > What's the easiest way to enforce the correct file dependencies > when building R > packages? > > cheers > David > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel