From ripley at stats.ox.ac.uk  Mon Jul 25 16:08:38 2005
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Mon, 25 Jul 2005 15:08:38 +0100 (BST)
Subject: [Rd] Rmath library problems
In-Reply-To: <OF188E7454.C4139FDB-ONC1257049.0048A7AB-C1257049.004AD55A@danskebank.dk>
References: <OF188E7454.C4139FDB-ONC1257049.0048A7AB-C1257049.004AD55A@danskebank.dk>
Message-ID: <Pine.LNX.4.61.0507251451150.4311@gannet.stats>

On Mon, 25 Jul 2005, Anders Brix Jensen wrote:

> Has anybody successfully called the Rmath library from C using the MS
> Visual Studio compiler (I am using Visual Studio 6.0)?
>
> I have compiled the Rmath library using gcc, and the 'test.c' program
> (which makes a call to qnorm) works fine when compiled with gcc. However,
> I get a fatal memory error when I run it after compiling it with Visual C.

What is `it'?  No interpretation I can make quite corresponds to the later 
comments.

> Would this memory problem be related to the compiler, or is it because I
> have not used the right compiler and/or linker options?

Probably the last.

> Two things puzzles me regarding compilation of Rmath:
> 1) The gcc compiler only seems to need the Rmath.dll to compile and
> execute. It needs neither Rmath.a nor Rmath.def.

> 2) The VC compiler needs a '.a'-file, but Rmath.a does not work (cannot
> find the symbols isnan and expm1). It compiles fine with libRmath.a
> however, but then it crashes as mentioned above.

These are actually statements about the linkers when linking against 
Rmath.dll, and not about compiling Rmath.  You should be linking a main 
function compiled under VC++ against a VC++ import library (which you can 
make from Rmath.def by lib /def:Rmath.def /out:Rmath.lib).  Then

cl /MT /Ox  /I..\..\include test.c Rmath.lib

works for me without any errors.

You can find all the background and hints in README.packages.

-- 
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



[Rd] Rmath library problems
Prof Brian Ripley