Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build GSL with msvc2010?

I'm working with Qt 4.8.3 and QtCreator, which I've compiled with msvc2010 as per the instructions here. Now however I need to link to GSL (Gnu Scientific Library), but currently I only know how to build it with g++ which produces linker errors just as described here, undoubtedly for the reason given in the answer by @EvanTeran. However, in my case, building Qt with g++ via cygwin is probably not an option--I've just come off a multi-day nightmare during which I tried to do just this, but could not, as recorded here. Surely there is a way to build gsl with msvc2010, but how? I have VS 2012 Express installed (though I've never used it before) in case there's a solution using it.

EDIT: Looking at CMake, it seems the best I can to is to manually create an entire hierarchy of CMakeLists.txt files for GSL. That's just a little too much so instead I've put a 100pt. bounty on the question mentioned above. Solving my problem the Visual Studio route (here) OR with g++ will get the bounty and the answer to both questions.

Update: The answer below worked great, but not seamlessly, possibly because I actually needed to compile under VS2012. A few tweaks to the code were required, such as explicit casts, which were tolerated under the previous compiler apparently but not mine. Otherwise things proceeded pretty smoothly.

like image 809
Matt Phillips Avatar asked Nov 07 '12 20:11

Matt Phillips


2 Answers

I have implemented CMake build support for GSL here: https://github.com/ampl/gsl

CMake can either generate a Visual Studio solution or NMake makefiles. For example:

> git clone git://github.com/ampl/gsl.git
> cd gsl
> cmake .
-- Building for: Visual Studio 10
-- Check for working C compiler using: Visual Studio 10
-- Check for working C compiler using: Visual Studio 10 -- works
...

This generates the solution (GSL.sln) and project files for Visual Studio 2010.

This CMake build script is now included in the contrib directory of the GSL Git repository git://git.savannah.gnu.org/gsl.git.

As of May 2014, building shared libraries (DLLs) is supported as well with GSL_SHARED option.

like image 151
vitaut Avatar answered Nov 12 '22 20:11

vitaut


You can use CMake and create your own build from this repository for whatever Visual Studio version you are using. Check out the answer by @vitaut for more details.

like image 44
Carsten Avatar answered Nov 12 '22 18:11

Carsten