windows下boost,pthread,clapack,jpeg,gsl的配置

15 篇文章 0 订阅
7 篇文章 0 订阅

1.boost

Boost是一个开源、可移植的强大的C++程序库,由C++标准委员会库工作组成员发起。官方网址为http://www.boost.org,SourceForge网址为http://sourceforge.net/projects/boost/。本文以Windows下Visual Studio为例讲解如何编译和配置Boost库。

首先从SourceForge上下载Boost库的压缩包,此时的最新版为1.47.0,下载地址为http://nchc.dl.sourceforge.net/project/boost/boost/1.47.0/boost_1_47_0.7z;下载后,解压缩7z包。然后以管理员方式在命令提示符下运行bootstrap.bat批处理文件,运行后会在当前目录中出现bjam.exe文件。

接着在命令行下运行bjam.exe,开始Boost库的编译,需要等待一段时间,编译完后提示如下:


这里提示我们要配置好编译器的头文件路径和库文件路径,这里我们打开Visual Studio,选择“工具”菜单,然后依次选择“选项”——“项目和解决方案”——“VC++目录”,添加Boost库文件目录和包含文件目录,确定即可。

下面就可以创建项目进行测试了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Boost shared_ptr测试
// http://www.programlife.net
#include <iostream>
#include <boost/shared_ptr.hpp>
using namespace std;
 
int main(int argc, char **argv)
{
	boost::shared_ptr<int> shptr(new int(10));
	cout << "use_count: " << shptr.use_count() << endl;
	cout << "value: " << *shptr << endl;
 
	return 0;
}

2.pthread

(1) 下载

下载地址:ftp://sourceware.org/pub/pthreads-win32

(2)安装pthreads-w32-2-8-0-release.exe

       双击pthreads-w32-2-8-0-release.exe,点击Browse选择安装到的目录,然后点击Extract解压,完成后点击Done。

       之后会在安装目录看到有三个文件夹Pre-built.2、pthreads.2、QueueUserAPCEx.

第一个是生成库(头文件和库文件那些),第二个是源码,第三个不清楚,像是测试程序。

       将Pre-built.2文件夹下的include和lib文件夹里的文件复制到VS2008对应的include和lib目录,我这里是C:\Program Files\Microsoft Visual Studio 9.0\VC\include和C:\Program Files\Microsoft VisualStudio 9.0\VC\lib.

 (3)测试程序

[cpp]  view plain cop
  1. #include<stdio.h>  
  2. #include<pthread.h>  
  3. #include<Windows.h>  
  4. #pragma comment(lib, "pthreadVC2.lib")  //必须加上这句  
  5.    
  6. void*Function_t(void* Param)  
  7. {  
  8.      pthread_t myid = pthread_self();  
  9.      while(1)  
  10.      {  
  11.          printf("线程ID=%d \n", myid);  
  12.          Sleep(4000);  
  13.      }  
  14.      return NULL;  
  15. }  
  16.    
  17. int main()  
  18. {  
  19.      pthread_t pid;  
  20.      pthread_create(&pid, NULL, Function_t,NULL);  
  21.      while (1)  
  22.      {  
  23.          printf("in fatherprocess!\n");  
  24.          Sleep(2000);  
  25.      }  
  26.      getchar();  
  27.      return 1;  
  28. }  
 和Linux的pthread一样~直接编译运行就ok了。如果运行提示缺少pthreadVC2.dll,就将Pre-built.2\lib目录下的pthreadVC2.dll拷贝到可执行文件所在目录就行了

3.clapack

(1)简介

     要了解CLAPACK,就要先知道什么是LAPACK。

     LAPACK(Linear Algebra PACKage)是一个高性能的线性代数计算库,以BLAS(Basic LinearAlgebra Subprograms)为基础,用Fortran语言编写,可用于计算诸如求解线性代数方程、线性系统方程组的最小平方解、计算特征值和特征向量等问题。而CLAPACK则是LAPACK的C语言接口。

 (2)安装

     搜了不少网页,终于找到一个方便的安装方法(http://icl.cs.utk.edu/lapack-for-windows/clapack/index.html#running)。这个安装方法在我的PC测试通过,PC的配置是Windows XP SP3,VC6。具体步骤如下:

  1. Download clapack-3.2.1-CMAKE.tgz and unzip.
  2. Download cmake and install it on your machine.
  3. Open CMAKE
    • Point to your CLAPACK-3.2.1-CMAKE folder in the source code folder
    • Point to a new folder where you want the build to be (not the same is better)
    • Click configure, check the install path if you want to have the libraries and includes in a particular location.
    • Choose Visual Studio Solution. You can also choose nmake or any other platform.
    • You may have to click again configure until everything becomes white
    • Click generate, that will create the Visual Studio for CLAPACK and you are done.
    • Close CMAKE
  4. Look in your "build" folder, you have your CLAPACK Visual Studio Solution, just open it.
  5. Build the "ALL_BUILD" project, it will build the solution and create the librarires
  6. Build the "INSTALL". This will put the libraries and include in your install folder.
  7. Build the "RUN_TESTS". The BLAS and CLAPACK testings will be run.

      如果没修改CMAKE中的设置,那么搞定第6个步骤后,你会在C:\Program Files\CLAPACK发现你所需要的*.h和*.lib

备注:在RUN_TESTS有部分不能通过,也不影响其余功能的正常使用

 (3)添加.h,.lib

  如同上面的方法,对生成的头文件和库文件,添加其包含目录和库目录(属性->vc++ ->包含目录/库目录)

4.jpeg

(1)下载源代码

下载地址:http://www.ijg.org/。注意:一定要下载win32 版本

(2)编译源代码.

    A、解压源代码,修改源代码中jconfig.vc为jconfig.h;

    B、添加环境变量PATH,X:/Program Files/Microsoft Visual Studio/VC98/Bin ;

    C、修改makefile.vc,将 Pull in standard variable definitions下面的一行换为:!include <X:/Program Files/Microsoft Visual Studio/VC98/Include/win32.mak> ;

    D、进入命令提示环境下,输入:vcvars32 回车,这是一个用来设置VC路径环境的批处理;

    E、编译生成库文件 命令:nmake /f makefile.vc nodebug=1;

(做这一步的时候一定要将命令提示环境的当前文件夹设为makefile.vc所在的文件夹)

nmake /f makefile.vc nodebug=1;末尾的封号一定不能丢,我就为此付出了惨痛的代价

这样就OK了

(3)jpeglib库VC下使用

对于库的使用只需要有相应的.lib文件和头文件就可以了。Vc中要添加libjpeg.lib库的连接

         将这几个文件拷贝到你的项目中:libjpeg.lib,jconfig.h,jmorecfg.h,jpeglib.h,在你需要进行压缩的文件中加入

extern "C" {

         #include "jpeglib.h"

        // #include "jmorecfg.h"

         //#include "jconfig.h"

}

5. gsl

1、从http://gnuwin32.sourceforge.net/packages/gsl.htm下载Complete package, except sourcesSources两个exe文件。

2 首先安装从http://gnuwin32.sourceforge.net/packages/gsl.htm下载的两个文件gsl-1.8.exegsl-1.8-src.exe

设置VS2010编译环境

 3、生成lib文件。发现安装目录lib下并没有libgsl.lib,libgslcblas.lib这两个文件,倒是有两个扩展名为defa(linux下库文件包格式)的文件,因此必须进行转换。

  开始菜单,要用VS带的CMD命令行去跑,不能用windows系统下的CMD!!!

 

  进入gsl库的lib目录下依次输入以下两条语句:
    lib /machine:i386 /def:libgsl.def
    lib /machine:i386 /def:libgslcblas.def (注意空格!!!)


再看lib目录下,发现有了libgsl.lib,libgslcblas.lib这两个文件。

 4

x:\Program Files\GnuWin32l\bin中的libgsl.dlllibgslcblas.dll复制到D:\Program Files\Microsoft Visual Studio 10.0\VC\Bin

在属性->配置属性->vc++目录->包含目录 里添加  D:\Program Files\GnuWin32\include

在属性->配置属性->vc++目录->库目录   里添加  D:\Program Files\GnuWin32\lib

在属性->配置属性->连接器->输入->附加依赖项 里添加  libgsl.lib  libgslcblas.lib


重要tips:需要在c/c++command line里添加  /D "GSL_DLL",(折磨我半个月!!!!!!!)

测试Gsl函数库

#define GSL_DLL
#include <gsl/gsl_spline.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <gl/glut.h>
#include <gl/gl.h>
void Display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    
const size_t n = 4;
    
double x[] = {0,0.333336,0.666666,1};
    
double y[] = {0,0.5,0.9,0};
    gsl_interp* interps[
3] = {NULL,NULL,NULL};
    interps[
0] = gsl_interp_alloc(gsl_interp_linear,n);
    interps[
1] = gsl_interp_alloc(gsl_interp_polynomial,n);
    interps[
2] = gsl_interp_alloc(gsl_interp_cspline,n);
    gsl_interp_init(interps[
0],x,y,n);
    gsl_interp_init(interps[
1],x,y,n);
    gsl_interp_init(interps[
2],x,y,n);
    gsl_interp_accel* acc = gsl_interp_accel_alloc();
    glBegin(GL_LINE_STRIP);
        
for(double t=0.0; t<=1.025; t+=0.025)
        
{
            glColor3f(
1,0,0);
            glVertex3f(t,gsl_interp_eval(interps[
0],x,y,t,acc),0.0);
        }
    glEnd();
    glBegin(GL_LINE_STRIP);
        
for(double t=0.0; t<=1.025; t+=0.025)
        
{
            glColor3f(
0,1,0);
            glVertex3f(t,gsl_interp_eval(interps[
1],x,y,t,acc),0.0);
        }
    glEnd();
    glBegin(GL_LINE_STRIP);
        
for(double t=0.0; t<=1.025; t+=0.025)
        
{
            glColor3f(
0,0,1);
            glVertex3f(t,gsl_interp_eval(interps[
2],x,y,t,acc),0.0);
        }
    glEnd();
    gsl_interp_accel_free(acc);
    gsl_interp_free(interps[
0]);
    gsl_interp_free(interps[
1]);
    gsl_interp_free(interps[
2]);
    glutSwapBuffers();
}
int main(int argc, char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
    glutInitWindowSize(
512,512);
    glutCreateWindow(
"GSL Interpolation");
    glutDisplayFunc(Display);
    glClearColor(
1,1,1,1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(-
1,-1,0);
    glScalef(
2,2,1);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glViewport(
0,0,512,512);
    glLineWidth(
4.0);
    glutMainLoop();
    
return 0;
}







  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值