1. Preface
GSL (GNU Scientific Library) is a library written in C for scientific computing. It has more than 1000 functions. It provides many mathematical computing aspects, most functions of MATLAB can be implemented by using it, which saves a lot of trouble in numerical calculation. Detailed functions of gsl. GSL functions and the introduction of the relevant header files can see this partial article: TTS, GSL document directory translation see here: http://blog.csdn.net/yruilin/article/details/3986844, we need to implement a mathematical function, for more information, see gsl.
GSL configurations on Windows platforms include many articles, such as common articles from vc6 to vs2010, which are not listed here. You can find them on Google or Baidu, but there is no configuration in the QT environment (at least I didn't see it). Although the configuration in QT and VS is similar, I still think it is necessary to write an article to describe it for your convenience.
2. Get GSL
: Http://gnuwin32.sourceforge.net/packages/gsl.htm
There are 6 items to download on this page, saving you the trouble to directly download the first "complete package, t sources. If you do not want to install packages, you can download "binaries" and "Developer Files". These two files contain compiled DLL files and. A and Def files (only lib ~~ is not available ~~). If the network is walled, see the attachment at the end of this article.
The GSL directory is shown in no matter how it is downloaded:
We will use the DLL under the "bin" directory, and under the "lib" directory ...... Def file (LIB file not provided officially ......), And header files under the "include" Directory
3. Generate the Lib File
Because lib files are not officially provided, You need to generate them by yourself. There are many ways to generate lib files using def files. Baidu Google has many methods. Here we will talk about it:
1. Start Menu, click Run, And Enter cmd
2. Enter the lib directory of The GSL library and enter the following two statements in sequence:
LIB/machine: i386/DEF: libgsl. Def
LIB/machine: i386/DEF: libgslcblas. Def
Look at the lib directory and find the libgsl. lib and libgslcblas. Lib files.
4. Configure GSL In the QT Environment
There are DLL, Lib, and header files. If everything is ready, qmake is worse.
The libgsl. lib and libgslcblas. Lib files under the "lib" directory and the header files under the include directory are used during the development process. Two DLL files under the bin directory are used during the runtime. For the scalability of program development, we can directly add The GSL folder to the project directory that requires gsl, copy the include folder and Lib folder in this folder.
As shown in: Create a GSL folder in a project and copy the include and Lib files to this folder. The structure is as follows:
Project
| _ GSL
| _ Include
| _ GSL
| _ Header file
| _ Lib
| _ Libgsl. lib and libgslcblas. Lib
To import the header files in include, you need to write the following in the Pro file:
INCLUDEPATH += $$PWD\gsl\includeLIBS += -L$$PWD\gsl\lib -llibgslLIBS += -L$$PWD\gsl\lib -llibgslcblas
In this way, you can use GSL, which is very simple. However, some functions need to use DLL. Therefore, to avoid unnecessary troubles, you need to predefine the macro gsl_dll. Therefore, the above pro file should be written as follows:
DEFINES += GSL_DLLINCLUDEPATH += $$PWD\gsl\includeLIBS += -L$$PWD\gsl\lib -llibgslLIBS += -L$$PWD\gsl\lib -llibgslcblas
Then it is completely OK.
Try the following code:
H:
#include <gsl/gsl_sf_bessel.h>#include <math>#include<iostream>
CPP:
int main(){ double x =5.0; double y =gsl_sf_bessel_J0 (x); cout<< "J0("<< x <<") = " << y<< endl; return0;}
The first run will crash directly, mainly because the DLL is not placed in the generated directory, and the DLL is placed in the corresponding directory to be executed normally.
5. Write the GSL pri file to simplify deployment steps
Thanks to qmake, you can easily organize the project structure. To facilitate future calls, we can write a gsl. PRI file in the GSL directory. You only need to include ($ PWD/GSL/gsl. PRI) for future use.
Defines + = gsl_dll # Some connection errors will occur when this sentence is not added: Export depath + =$ $ PWD \ export dedependpath + =$ $ pwdlibs + =-L $ PWD \ Lib-llibgsllibs + = -L $ PWD \ Lib-llibgslcblas
6. video tutorial below is a video tutorial of configuration: http://v.youku.com/v_show/id_XNzc5MjU1NzEy.html
Through this method can easily configure a lot of libraries, along with a QT under the configuration of blitz ++ mathematical library method: http://v.youku.com/v_show/id_XNjk4NDA3NDQw.html
7. Demo download demo (including GSL required DLL and Lib files): http://download.csdn.net/detail/czyt1988/7893997
Deployment in the QT environment of the strongest mathematical library GSL (GNU Scientific Library)