C/C++ Libraries for Windows
Work in progress.
Not all C/C++ library-writers are particularly helpful when in comes to producing versions that work pleasant across different platforms and compilers. But often it's not as difficult or impossible as it's made out to be - in fact, sometimes it's really very easy. On this page, I'm gathering some libraries that I've rebuilt for Visual Studio, which hopefully will make life easier.
GSL
I used the instructions provided by Brian Gladman here, to build binaries of GSL 1.16, for Visual Studio 2013 and 2015. To use them in Visual Studio, do the following steps. I'm assuming you vaguely know what you're doing in Visual Studio.
- Download the GSL binaries for VS2013 or VS2015.
- Unzip them somewhere - purely for example in these steps, I'll assume you unzipped them into C:\VSGSL.
- Open your Visual Studio project. On the drop-downs at the top, note whether you're in Release or Debug mode, and whether you're compiling for x64 or Win32. The final step is different depending on these selections, and you may want to repeat the following steps for each combination you're going to use.
- From the Project Menu, go to the "Project" Preferences at the bottom - where "Project" is whatever your Project is called.
- Choose C/C++, General, and look at the Additional Include Directories field. It's semi-colon separated. Insert (for example) C:\VSGSL\include; at the start.
- Choose Linker, Input, and insert gsl.lib;cblas.lib; into the semi-colon separated list of libraries.
- Choose Linker, General, and look for Additional Library Directories. Now, depending on your configuration, insert one of the following:-
- Release-mode, 64-bit (x64). Insert C:\VSGSL\lib\x64_release;
- Debug-mode, 64-bit (x64). Insert C:\VSGSL\lib\x64_debug;
- Release-mode, Win32 (a.k.a x86). Insert C:\VSGSL\lib\x86_release;
- Debug-mode, Win32. Insert C:\VSGSL\lib\x86_debug;
- Done. Build your code. I suggest also in C/C++, Code Generation, set Runtime Library to either Multi-threaded if you're in the release configuration, or Multi-threaded Debug if you're in the debug configuration - that is, remove the dependency on Visual Studio's runtime DLLs. That will make things easier all round.
- Here's some example code that now compiles.
#include <gsl/gsl_rng.h> int main() { int seed = 12345; gsl_rng_env_setup(); gsl_rng *r = gsl_rng_alloc(gsl_rng_default); gsl_rng_set(r, (unsigned long)seed); for (int i = 0; i<100; i++) { double v = gsl_rng_uniform(r); printf("%lf\n", v); } gsl_rng_free(r); return 0; }
BOOST
All the requests for Boost I've had so far, have been for the "basic" parts of the library, which turn out to be portable header files. There are other parts of Boost that need special compiling, but here are the simple instructions, and if there's a need for the advanced ones, I'll return to it later. So, to use Boost in any Visual Studio version:
- Download Boost from www.boost.org
- Unzip it somewhere. Again, I'll assume a dummy directory of C:\Boost.
- Have a look at the Boost stuff you unzipped. Mine was v1.63, and it made a folder C:\Boost\boost_1_63_0 - this may have changed by the time you do it, but the pattern should be obvious.
- Open your Visual Studio project.
- From the Project Menu, go to the "Project" Preferences at the bottom - where "Project" is whatever your Project is called.
- Repeat this for each Configuration and Platform combination you want:
- Choose C/C++, General, and look at the Additional Include Directories field. It's semi-colon separated.
- For my example, I inserted C:\Boost\boost_1_63_0; at the start. This will be right if you have code that contains, for example,
#include <boost/locale.hpp> #include <boost/algorithm/string.hpp>
- Rebuild!