bug-gsl
[Top][All Lists]

## [Bug-gsl] Bug report with VC7

 From: Vincent Sacksteder Subject: [Bug-gsl] Bug report with VC7 Date: Wed, 5 Mar 2003 21:02:28 +0100

Dear GSL developers, thanks for all your work.  I just installed your
library and started using it with the Microsoft VC7 compiler.  I created a
little exe which uses the random functions:

#include "stdafx.h"
#include <gsl_randist.h>

int _tmain(int argc, _TCHAR* argv[])
{
const gsl_rng_type * T;
gsl_rng * r;

double sigma = 1.0;
double result;
int i;

/* create a generator chosen by the
environment variable GSL_RNG_TYPE */

gsl_rng_env_setup();

T   = gsl_rng_mt19937;
r = gsl_rng_alloc (T);

/* print n random variates chosen from
the poisson distribution with mean
parameter mu */
for (i = 0; i < 10; i++)
{
result = gsl_ran_gaussian (r, sigma);
/*p(x) dx = {1 \over \sqrt{2 \pi \sigma^2}} \exp (-x^2 / 2\sigma^2) dx */
printf("%.5f\n", result);
}

return 0;
}

The bug I am reporting is that the linker is unable to find gsl_rng_mt19937,
or any other constant, in the gsl.lib or gsl.dll.  It is, however, able to
find all the functions exported by gsl.dll.  And I checked that it wasn't a
problem with my compile settings by switching to ANSI compatibility mode and
also requiring the compiler to treat all my code as C code.

Finally I was able to get it working by doing the following: in gsl_types.h,
on line 33, if _DLL is undefined then GSL_VAR is defined as extern.  This
means that my exe is using constants defined as extern, while the dll is
using constants defined as extern __declspec(dllexport).  So I just added
__declspec(dllimport) to line 33 of gsl_types.h.  So now gsp_types.h lines
#ifdef WIN32
#  ifdef _DLL
#    ifdef DLL_EXPORT
#      define GSL_VAR extern __declspec(dllexport)
#    else
#      define GSL_VAR extern __declspec(dllimport)
#    endif
#  else
#    define GSL_VAR extern __declspec(dllimport)
#  endif
#else
#  define GSL_VAR extern
#endif

So it looks like the gsl macros are a little messed up for use in client
exes.  I would suggest this small change, supposing of course it doesn't
break anything else.  I suppose you haven't seen this yet because it is a
WIN32 problem.

If you're interested, VC7 was able to compile the gsl.dll  and gslcblas.dll
with no problem.  It does report over 100 warnings while in /W3 warning mode
though, almost all of which are implicit type casting.  However there are a
few others that could be more serious.  I'm including the report as an html
file.

Also I've noticed that I had to change a few includes to not refer to the
parent directory, for instance changing #include <gsl/gsl_errno.h> to
#include <gsl_errno.h>.  However this may be my fault.

Peace,
Vincent Sacksteder



BuildLogwarnings.htm
Description: Text document