levmar怎么在vs2019配置 - 爱问答

(爱问答)

levmar怎么在vs2019配置

本人c++渣渣,用的是2019版的vs,运行师兄的代码时显示“无法打开头文件“levmar.h””,求助各位大神如何配置levmar库

准备工具:

1. cmake-2.8.12.1-win32-x86.zip (选择Binarydistributions栏下的第二个)。

2. clapack-3.2.1-CMAKE.tgz(页面做的稍乱,找到同名的那个压缩包下载)。

3. levmar-2.6

 

步骤:

1.  先将上面下载的三个压缩包都解压。解压后的cmake-2.8.12.1-win32-x86是编译工具,建议放在常用的工具文件夹下(英文目录,不要有中文)。解压后的clapack-3.2.1-CMAKE和levmar-2.6等会要用到,而且编程的时候也用到其做包含目录,因此不建议放在桌面。

2.  针对clapack-3.2.1-CMAKE的操作。双击打开cmake-gui.exe(该文件在cmake-2.8.12.1-win32-x86文件夹里的bin文件夹下)首先要对clapack-3.2.1-CMAKE进行编译。如图:levmar怎么在vs2019配置

 

   对于箭头1,点击右边的BrowseSource...将文件夹定位到第一步解压出的clapack3.2.1-CMAKE,对于箭头2,Browse Build..则是你要编译到的位置,为了方便我选择C:CLAPACK。选择完之后,点击左下角的configure按钮,弹出的框里我们选择visual studio 10 Win64,点Finish等几秒钟,Configure结束后画面中间会出来一些红色的条框,不管它,再点Configure右边的Generate按钮,根据下面提示Generate done后,可以先关掉这个窗口了。现在我们到C:CLAPACK下,找到CLAPACK.sln这个文件,并双击,这时候会在VS2010里出来一个工程,等待加载完成后,选择生成解决方案。这里需要花点时间,等程序跑完之后会提示成功了33个项目(这一步是为了生成4个lib文件)。下面可以先关掉VS2010。然后再次到C:CLAPACK文件夹下,要寻找4个.lib文件(为了在levmar中要链接他们),这4个文件分别是:

l C:ClapackBLASSRCDebug:       blas.lib

l C:ClapackF2CLIBSlibf2cDebug:    libf2c.lib

l C:ClapackSRCDebug:              lapack.lib

l C:ClapackTestingMATGENDebug:     tmglib.lib

为了便于我们在后面链接他们,先在C:CLAPACK下新建一个LIB文件夹,然后复制上面四个lib文件到这个文件夹下。到这里第二步基本完成了。

注意:复制libf2c.lib的时候我们将文件名改为f2c.lib(因为后面链接的默认名是f2c.lib)

 

3.   针对LEVMAR2.6部分接下去再次打开cmake-gui.exe,Browse Source...选择第一步解压出来的levmar-2.6,Browse Build..选择要编译到的位置,这里我选的是C:lm26。然后点击Configure,选择visual studio 10 Win64,之后弹出如下所示:

 levmar怎么在vs2019配置

 

将LAPACKBLAS_DIR 后面的usr/lib文件夹路径改成第二步中我们自己建的那个文件夹路径 C:CLAPACKLIB。然后再次点击左下角的Configure,红色变白色,之后再点击Generate。下面到 C:lm26文件夹下找到LEVMAR.sln文件,运行它,点生成解决方案,全部成功后关掉。这一步是为里生成C:lm26Debuglevmar.lib文件。到这里配置部分基本完成了,下面讲如何在我们自己的程序里用。

4.  新建一个VS2010的c++工程lm_test,点顶部菜单栏的项目,再点属性,点左侧的配置属性,再点右侧的配置管理器,点活动平台解决方案的下拉菜单,点新建,然后把Itanium换成x64点确定,如图levmar怎么在vs2019配置

 

这样,就将我们的工程配置成了64位的。

然后右键点击左侧解决方案资源管理器中lm_test,选择属性,弹出的窗口左侧点击配置属性下的vc++目录,然后在右侧的包含目录中添加我们在第一步中解压出的levmar2.6的文件夹;

 

确定后,再在库目录下再添加两个文件夹,一个是我们在第二步中自己新建的那个C:CLAPACKLIB,另一个是C:lm26Debug,为的就是这两个文件夹里面的lib文件;

 

确定后我们点击左侧的链接器、输入,附加依赖项添加第二步生成4个lib文件和第三步生成的1个lib文件: lapack.lib, blas.lib, f2c.lib,tmglib.lib.levmar.lib。

现在把下面的程序拷贝进去运行看看吧。(可以对比 levmar-2.6 里面的 expfit.c  )

// testlevmar.cpp : Defines the entry pointfor the console application.

//

////////////////////////////////////////////////////////////////////////////////////

// Example program that shows how to use levmar in order to fit the three-

// parameter exponential model x_i = p[0]*exp(-p[1]*i) + p[2] to a set of

// data measurements; example is based on a similar one from GSL.

//

// Copyright (C) 2008-11  ManolisLourakis (lourakis at ics forth gr)

// Institute of Computer Science, Foundation for Research & Technology- Hellas

// Heraklion, Crete, Greece.

//

// This program is free software; you can redistribute it and/or modify

// it under the terms of the GNU General Public License as published by

// the Free Software Foundation; either version 2 of the License, or

// (at your option) any later version.

//

// This program is distributed in the hope that it will be useful,

// but WITHOUT ANY WARRANTY; without even the implied warranty of

// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

// GNU General Public License for more details.

//

////////////////////////////////////////////////////////////////////////////////////

#include <stdio.h> 

#include <stdlib.h>

#include <string.h>

#include <math.h>

#include "levmar.h"

#ifdef _cplusplus

extern "C"{

#include "f2c.h"

#include "clapack.h"

}

#endif

 

#ifndef LM_DBL_PREC

#error Example program assumes that levmarhas been compiled with double precision, see LM_DBL_PREC!

#endif

#define M_PI 3.14

 

#undef REPEATABLE_RANDOM

#define DBL_RAND_MAX (double)(RAND_MAX)

#ifdef _MSC_VER // MSvc

#include <process.h>

#define GETPID  _getpid

#elif defined(__GNUC__) // GCC

#include <sys/types.h>

#include <unistd.h>

#define GETPID  getpid

#else

#warning Do not know the name of thefunction returning the process id for your OS / compiler combination

#define GETPID  0

#endif

#ifdef REPEATABLE_RANDOM

#define INIT_RANDOM(seed) srandom(seed)

#else

#define INIT_RANDOM(seed)srandom((int)GETPID()) // seed unused

#endif

 

double gNoise(double m, double s)

{

         doubler1, r2, val;

         r1= ((double)rand()) / DBL_RAND_MAX;

         r2= ((double)rand()) / DBL_RAND_MAX;

         val= sqrt(-2.0*log(r1))*cos(2.0*M_PI*r2);

         val= s*val + m;

         returnval;

}

 

struct xtradata{

         charmsg[128];

 

};

 

void expfunc(double *p, double *x, int m,int n, void *data)

{

         registerint i;

         structxtradata *dat;

         dat= (struct xtradata *)data;

 

         for(i = 0; i<n; ++i)

         {

                   x[i]= p[0] * exp(-p[1] * i) + p[2];

    }

}

 

/* Jacobian of expfunc() */

void jacexpfunc(double *p, double *jac, intm, int n, void *data)

{

         registerint i, j;

         structxtradata *dat;

         dat= (struct xtradata *)data;

 

         /*fill Jacobian row by row */

         for(i = j = 0; i<n; ++i)

         {

                   jac[j++]= exp(-p[1] * i);

                   jac[j++]= -p[0] * i*exp(-p[1] * i);

             jac[j++] = 1.0;

    }

}

int main()

{

         constint n = 40, m = 3; // 40 measurements, 3 parameters

         doublep[m], x[n], opts[LM_OPTS_SZ], info[LM_INFO_SZ];

         registerint i;

         intret;

         structxtradata data;

 

         /*generate some measurement using the exponential model with

         *parameters (5.0, 0.1, 1.0), corrupted with zero-mean

         *Gaussian noise of s=0.1

         */

         //INIT_RANDOM(0);//这个地方源程序是没注释掉的

         for(i = 0; i<n; ++i)

                   x[i]= (5.0*exp(-0.1*i) + 1.0) + gNoise(0.0, 0.1);

 

         /*initial parameters estimate: (1.0, 0.0, 0.0) */

         p[0]= 1.0; p[1] = 0.0; p[2] = 0.0;

 

         /*optimization control parameters; passing to levmar NULL instead of opts revertsto defaults */

         opts[0]= LM_INIT_MU; opts[1] = 1E-15; opts[2] = 1E-15; opts[3] = 1E-20;

         opts[4]= LM_DIFF_DELTA; // relevant only if the finite difference Jacobian version isused

 

         strcpy_s(data.msg,"Hello there!");

 

         /*invoke the optimization function */

         ret= dlevmar_der(expfunc, jacexpfunc, p, x, m, n, 1000, opts, info, NULL, NULL,(void *)&data); // with analytic Jacobian

         //ret=dlevmar_dif(expfunc,p, x, m, n, 1000, opts, info, NULL, NULL, (void *)&data); // withoutJacobian

         printf("Levenberg-Marquardtreturned in %g iter, reason %g, sumsq %g [%g] ", info[5], info[6],info[1], info[0]);

         printf("Bestfit parameters: %.7g %.7g %.7g ", p[0], p[1], p[2]);

        

         system("pause");

         exit(0);

}


相关标签:配置

下一篇:大数据如果无法用单台的计算机进行处理,那是采用什么架构?

上一篇:Linux使用signal调用中断处理函数

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?