Re: [Rd] Makefile for embedding OpenBUGS in R package

From: Tobias Verbeke <>
Date: Mon, 06 Aug 2007 14:30:41 +0000

>----- Oorspronkelijk bericht -----
>Van: Prof Brian Ripley []
>Verzonden: maandag, augustus 6, 2007 03:46 PM
>Aan: 'Tobias Verbeke'
>Onderwerp: Re: [Rd] Makefile for embedding OpenBUGS in R package
>On Mon, 6 Aug 2007, Tobias Verbeke wrote:
>> Dear list,
>> I'm trying to embed OpenBUGS in an R package for use of it
>> on 64-bit Linux. In order to get the CLI working one has to
>> compile C code contained in $OpenBUGS/Manuals/CBugs.html
>same as
>I presume.

Actually, these files appear to differ. The file I referred to was the file ./Manuals/CBugs.html contained in the current OpenBUGS release:

>> (copied to say CBugs.c) using
>> gcc -m32 -o bugs CBugs.c -ldl
>> I put the OpenBUGS distribution in the ./inst subdirectory of
>> the package root. Where should I now put the CBugs.c and how
>Why do you want to install CBugs.c?

The CBugs.c file itself is indeed not needed in the built package.

>> should the Makefile look like in order to be able to call
>> $PKG_ROOT/OpenBUGS/bugs afterwards ?
>> Naively putting the following Makefile in ./src does not work
>What does 'does not work' mean? It's hard to know whether this is just
>not doing what you wanted, or something else is wrong.

Apologies. This is the error message when putting the Makefile in ./src and launching the package checker:

$ R.250 CMD check CGHmix

* checking for working latex ... OK
* using log directory '/home/tverbek1/pkg/CGHmix.Rcheck'
* using R version 2.5.0 (2007-04-23)
* checking for file 'CGHmix/DESCRIPTION' ... OK
* checking extension type ... Package
* this is package 'CGHmix' version '0.1-2'
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking whether package 'CGHmix' can be installed ... ERROR
Installation failed.
See '/home/tverbek1/pkg/CGHmix.Rcheck/00install.out' for details.

The file 00install.out contains:

>> -%--------
>> bugs: ../inst/OpenBUGS/CBugs.c
>> gcc -m32 -o bugs ../inst/OpenBUGS/CBugs.c -ldl
>> -%-------
>> The objective is to use something along the following
>> execfile <- system.file("OpenBUGS", "bugs", package = mypkg)
>> system(paste(execfile, "< somescript.script > somefile.out"))
>> This system call to the CLI is currently the only (non-WINE)
>> way of using OpenBUGS on Linux in batch mode.
>I think you need to make ../inst/OpenBUGS/bugs, not src/bugs. So
>something like
>all: ../inst/OpenBUGS/bugs
>../inst/OpenBUGS/bugs: ../inst/OpenBUGS/CBugs.c
> gcc -m32 -o ../inst/OpenBUGS/bugs ../inst/OpenBUGS/CBugs.c -ldl

Thank you.

>However, -m32 builds a 32-bit executable on 64-bit linux. Is that what you

Yes. The shared object ( comes with the OpenBUGS distribution and currently can only be cross-compiled by the main OpenBUGS developer (Andrew Thomas) who knows all secrets of the Windows only BlackBox (nomen omen) Component Pascal compiler.

$ file ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), stripped

Many thanks for your ever instructive answer.


P.S. Contents of CBugs.c from OpenBUGS distribution (3.0.1)

/* GNU General Public Licence    

   This small C program loads the ELF shared library and calls the CLI function.    Save it as a .c file and then compile it on Linux using gcc -o bugs CBugs.c -ldl


#include <dlfcn.h>
#include <stdio.h>
#include <string.h>

int main (int argc, char **argv)
  void * handle;
  void (*cli)(void);

  handle = dlopen("./", RTLD_LAZY);   if (!handle)
    return 1;

  return 0;    


>Brian D. Ripley,
>Professor of Applied Statistics,
>University of Oxford, Tel: +44 1865 272861 (self)
>1 South Parks Road, +44 1865 272866 (PA)
>Oxford OX1 3TG, UK Fax: +44 1865 272595
> mailing list Received on Mon 06 Aug 2007 - 22:37:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 06 Aug 2007 - 22:38:38 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.