Thursday, August 24, 2006

C/C++ GNU Scientific Library(GSL) for Windows

The GNU Scientific Library (GSL) is a numerical library for C and C++ programmers. It is free software under the GNU General Public License.

The library provides a wide range of mathematical routines such as random number generators, special functions and least-squares fitting. There are over 1000 functions in total with an extensive test suite.

GNU Scientific Library (GSL) 是一個內含許多數值及科學運算函式的 C/C++ 函式庫,內含超過 1000 個以上的函式(例如︰數值微分小波轉換排序..等等) ,並且可以使用在各種作業系統平台。
GSL 在 Windows開發環境下的使用 中有簡單說明如何在 Windows 環境使用 GSL ,以下則是再詳細一點介紹如何在 Visual C++ 6.0 的 IDE (整合型視窗介面) 下使用︰

1. 首先到 http://gnuwin32.sourceforge.net/packages/gsl.htm 下載 BinariesDeveloper files
2. 將 Binaries package 內 bin 子目錄下的 libgsl.dll, libgslcblas.dll 兩個檔案複製到 C:\Windows\System32 中。
3. 將 Developer files 解壓縮後,在 VC 的 IDE 中設定 include, lib 子目錄的路徑。
4. 由於此版本的 lib 子目錄中不含 .lib 檔,必須用以下指令產生。請先開啟 DOS 模式視窗(附屬應用程式/命令提式字元),切換目錄到 lib 目錄下,並下達︰
lib /machine:i386 /def:libgsl.def
lib /machine:i386 /def:libgslcblas.def
即可產生 libgsl.lib, libgslcblas.lib 兩個檔案。
5. 在 VC 專案中加入 libgsl.lib, libgslcblas.lib 這 2 個 lib 到 link 參數中。
6. 在 VC 專案的 Preprocessor definitions 中加入 GSL_DLL。
6. 可用函式及說明請見 Reference Manual

ps. GSL是使用C語法寫成,故並沒有使用類別(class),而是以結構(struct)及函式(function)組成,不過 GSL 仍可以用在 C++ 編繹器,並與 C++ 程式相容。

16 comments:

Anonymous said...

Hi Chinson,

I am having trouble generating LIB files from DEF files thru DOS.

I get error message like this...

LIB : warning LNK4012: invalid value "i386/def:libgsl.DEF", must be ALPHA, ARM,IX86, MIPS, MIPS16, MIPSR41XX, PPC, SH3, or SH4; option ignored

Do you know know what's causing me this problem?

or can I use the lib file generate from other's computer?

Thanks for your time and effort
My email is
9mbt1@qlink.queensu.ca

Brady

chinsonyeh said...

Hi Brady,
I am not familiar with this kind of problem. But here is my lib files. Hope they help.

libgsl.lib
libgslcblas.lib

Unknown said...

thx alot for teaching me these lines:
lib /machine:i386 /def:libgsl.def
lib /machine:i386 /def:libgslcblas.def

Anonymous said...

Hi, Chinson,

I am using VS 2005. How should I do 5. and 6.,
5. 在 VC 專案中加入 libgsl.lib, libgslcblas.lib 這 2 個 lib 到 link 參數中。
6. 在 VC 專案的 Preprocessor definitions 中加入 GSL_DLL。
?
I am kind of new to VC++, so could you explain it in a little bit more detailed?

thanks a lot!

Jerry

chinsonyeh said...

Hi Jerry,
First, you have to open the "Property Pages" from the main menu : "Project" -> "Properties".
In the property pages, go to "Configuration Properties"->"Linker"->"Input" and add "libgsl.lib libgslcblas.lib" into the "Additional Dependences" attribute.
Go to "Configuration Properties"->"C/C++"->"Preprocessor" and add "GSL_DLL" into the "Preprocessor Definitions".
By the way, you can also add additional include directory in "Configuration Properties"->"General".

Anonymous said...

thanks, Chinson!

Anonymous said...

when running "gsl_rng_alloc()",crashes happen,tip:a fatal error! ?? thanks!

chinsonyeh said...

Please make sure that you have added "GSL_DLL" in "Preprocessor definitions".
I got the same problem before doing it.

Anonymous said...

Hi Chinson
感謝您的教學
讓小弟第一次使用library就可以很快上手
另外想詢問一下
你的教學使用到的gsl文1.8版
若我想要升級到吹新的1.10版的話該如何做

brayn

chinsonyeh said...

Hi brayn,
我查了一下 GSL for Windows 的網站(http://gnuwin32.sourceforge.net/packages/gsl.htm),目前最近版還是在 1.8 喔,你說的 1.10 應該是指 Linux 版的。從 GSL 的官方網站說明來看(http://www.gnu.org/software/gsl/),如果要使用 GSL 1.10 版,可能要透過 Cygwin 的方式。不過這部份我沒有研究過,並不清楚是不是能直接套用到 Visual C++ 中使用 。

Anonymous said...

謝謝您的回覆
另外想在詢問
小弟拿了GSL Reference Manual裡面用來求eigenvalue和eigenvector的範例來測試
在compiler和build的時後都正常沒問題
為何執行後會出現下圖的錯誤
http://www.imagehostingsite.com/images/znmqtzmmnuh2yrz2zmjw.jpg

brayn

chinsonyeh said...

抱歉,我的功力不足,幫不上忙了。我拿該範例程式在 Linux 下用 gcc 編譯,程式是可以正確執行的,不過拿到 MSVC 2005 編譯跟執行,會有相同的問題。這部份恐怕要找真正的高手問了..

Anonymous said...

Hi,

Adding a simple line "#define WIN32" in your source code or "GSL_DLL" in "Preprocessor definitions" would probably eliminate many problems when using Visual Studio.

michelle said...

您好
想請問一下

您說由於此版本的 lib 子目錄中不含 .lib 檔,必須用以下指令產生。請先開啟 DOS 模式視窗(附屬應用程式/命令提式字元),切換目錄到 lib 目錄下
可是我不知道要怎麼切換到這個目錄下
我的路徑是以下
C:\Program Files\Microsoft Visual Studio 9.0\VC\lib
謝謝!

chinsonyeh said...

To michelle:

cd "C:\Program Files\Microsoft Visual Studio 9.0\VC\lib"

即可

michelle said...

謝謝!^^