15

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.

Community
  • 1
  • 1
Matt Phillips
  • 9,465
  • 8
  • 44
  • 75

2 Answers2

21

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.

vitaut
  • 49,672
  • 25
  • 199
  • 336
  • Thanks vitaut. I trust you have tried it out with a test program? And this this also include gsl_cblas? (Not that it isn't already useful.) – Matt Phillips Jan 22 '13 at 21:07
  • 1
    I am using it myself and the tests that come with GSL are handled in the CMake script so you can build and run them. gslcblas is included as well. – vitaut Jan 22 '13 at 21:24
  • pity doesnot support dll. I added line to set dll on, but got error when linking. – squid May 15 '13 at 07:45
  • @squid Try adding SHARED to add_library: add_library(gsl SHARED ${GSL_SOURCES}) – vitaut May 15 '13 at 14:32
  • 1
    Just now I managed to build gls on windows very easily. Your work is really helpful. Thank you! – hkuwenchao May 07 '15 at 13:43
  • @hkuwenchao Great. Don't forget to cast your vote if it was helpful =) – vitaut May 07 '15 at 13:57
  • 1
    @vitaut thanks for sharing your work. I got it from master/contrib and it was really useful. I greatly appreciated the RUN_TESTS project. – Francesco Sep 01 '15 at 14:06
4

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.

Carsten
  • 11,287
  • 7
  • 39
  • 62
  • You'll get this bounty as soon as the system lets me award it. Nice find, though I had to do a little tweaking (will describe shortly). – Matt Phillips Nov 20 '12 at 07:30
  • Seems like the site has moved to http://brgladman.org/oldsite/computing/gnu_scientific_library.php – NIA May 11 '14 at 15:17
  • 2
    This answer is a exemplifies why link only answers lose their value over time. – Sinan Ünür Apr 11 '16 at 14:10
  • 7
    Link is broken. – atzol Jun 16 '16 at 20:57
  • 1
    Link is now clickbait, and has dangerous risk – Grandtour Dec 16 '18 at 19:31
  • @Grandtour thanks for the info. This answer is a few years old now and using CMake, like vitaut suggested in his answer is more straightforward and should be preferred. All credits to him! Of course I've removed the old URL from the post. – Carsten Dec 17 '18 at 16:53