1 我的gsl安装路径:D:/GnuWin32
1 eclipse 新建c++ project Helloworld类型的工程,取名gsl_test;
2 设置工程属性,将gsl 添加到工程中。
2.1 project-->properties--->C/C++ builder--->GCC C++ complier --->Includes
添加"D:/GnuWin32/include"
2.2 project-->properties--->C/C++ builder--->GCC complier --->Includes
添加"D:/GnuWin32/include"
2.3 project-->properties--->C/C++ builder---> MinGW C++ Linker---->Libraries
2.3.1 在libraries(-l)中添加 (1) gsl (2) gslcblas
注: 在GnuWin32的lib目录下会有libgsl.a 和libcblas.a 两个静态库,mingw链接该静态库时,会自动去掉libgsl 与libgslcblas的lib.而mingw实际上的链接的库文件名为-lgsl -lgslcblas. 如果在Dev-cpp下使用过gsl,Devcpp使用的编译器其实也是mingw。google 牛人的bolg 上面都会提醒要在linker command line 上添加 -lgsl -lgslcblas。mingw在编译时调用库的函数为:mingw32/bin/ld.exe,给ld.exe 提供的命令行应该就是库的名字,该命令行要有如下格式: -lxxx,它在实际的静态库中对应的库文件为libxxx.a。而eclipse直接加上了-l 所以只需要提供xxx 作为库文件名。
2.3.2 在library search path中添加 "D:/GnuWin32/lib" 也就是把libgsl.a 与libgslcblas.a的路径告诉编译器。
3 点击apply 确定。使用如下测试代码。
#include <iostream>
#include<gsl/gsl_matrix.h>
using namespace std;
int main() {
gsl_matrix *ma
= gsl_matrix_alloc (2, 2);
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
1.新建C Project
2.HELLO WORLD ANSI C PROJECT Tool chains LINUX GCC
3.通过文件系统导入代码
4.对着工程点property,C++ BUILD->SETTING->Tool Setting->include 设置/usr/include/gsl
5.GCC C Linker -l中 添加 gsl gslcblas m -L中填写 /usr/lib