This is the mail archive of the mailing list for the GSL project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Solution: Setting up GSL on Windows with VisualStudio

It has taken me several hours to figure out how to compile an example program with Microsoft Visual C++ (.NET 2003), a.k.a. MSVC, and GSL. Since others on this list have expressed their frustration at the task, I'll describe my solution, which is probably only one of many. This is done in detail for those who may not have used MSVC before. Also keep in mind that I am new at this myself.

1. Download and install
(For more info, see

2. Within VisualStudio, go to File->New->Project, then "Visual C++ Projects," then "Win32," then "Win32 Console Application." Enter a name and click "OK." On the next screen click "Finish."

3. In the "Solution Explorer," right click on the name of your project and go to "Properties."

4. Under Configuration Properties->Linker->General->Additional Library Directories, type in "C:\Program Files\GnuWin32\lib"

5. Under Configuration Properties->Linker->Input->Additional Dependencies, type in "libgslcblas.a libgsl.a"

6. Under Configuration Properties->C/C++->General->Additional Include Directories, type in "C:\Program Files\GnuWin32\include"

7. Under Configuration Properties->C/C++->Code Generation->Runtime Library, select "Multi-threaded DLL"

8. Replace the main .cpp file with something like the following:
(Adapted from

#include "stdafx.h"
#include <gsl/gsl_poly.h>

int _tmain(int argc, _TCHAR* argv[])
  int i;
  /* coefficient of P(x) =  -1 + x^5  */
  double a[6] = { -1, 0, 0, 0, 0, 1 };  
  double z[10];

  gsl_poly_complex_workspace * w 
      = gsl_poly_complex_workspace_alloc (6);
  gsl_poly_complex_solve (a, 6, w, z);

  gsl_poly_complex_workspace_free (w);

  for (i = 0; i < 5; i++)
      printf ("z%d = %+.18f %+.18f\n", 
              i, z[2*i], z[2*i+1]);

  return 0;

9. Hit F7 to build your program. You should now be able to run it from the command line. You'll get a result like the following:

z0 = -0.809016994374947670 +0.587785252292473360
z1 = -0.809016994374947670 -0.587785252292473360
z2 = +0.309016994374947510 +0.951056516295152980
z3 = +0.309016994374947510 -0.951056516295152980
z4 = +0.999999999999999890 +0.000000000000000000

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]