在Windows上使用Visual Studio的Fortran项目中使用Nlopt库

时间:2017-04-08 20:49:55

标签: windows visual-studio fortran nlopt

我一直在我的Fortran项目中使用NLopt library,在Linux系统下运行它没有问题。现在我开始在Windows上使用Visual Studio来编写我的Fortran程序。但是,我在Windows上使用NLopt库时遇到了一些困难。我在我的计算机上使用Visual Studio 2013和Intel Parallel Studio XE 17。

以下是我所做的以及遇到的问题:

  1. 我从其网站下载了Windows版本(64位)的NLopt库。然后我使用VS的开发人员命令提示符来执行lib /def:libnlopt-0.def \MACHINE:x64,并在同一文件夹下创建.lib和.exp文件。

  2. 我在Visual Studio中创建了一个Fortran项目,并使用了在Linux下运行的代码。在Visual Studio中,我将.lib和.exp的路径添加到"其他包含目录"和#34;其他图书馆目录"到项目属性。我还添加了" libnlopt-0.lib"和" libnlopt-0.exp"到"附加依赖"。

  3. 编译项目时,它失败并显示错误:

    1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_CREATE referenced in function MOD_NLOPT_mp_SUB_NLOPT
    1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_SET_FTOL_ABS referenced in function MOD_NLOPT_mp_SUB_NLOPT
    1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_SET_FTOL_REL referenced in function MOD_NLOPT_mp_SUB_NLOPT
    1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_SET_XTOL_ABS referenced in function MOD_NLOPT_mp_SUB_NLOPT
    1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_SET_XTOL_REL referenced in function MOD_NLOPT_mp_SUB_NLOPT
    1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_SET_LOWER_BOUNDS referenced in function MOD_NLOPT_mp_SUB_NLOPT
    1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_SET_UPPER_BOUNDS referenced in function MOD_NLOPT_mp_SUB_NLOPT
    1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_SET_MAX_OBJECTIVE referenced in function MOD_NLOPT_mp_SUB_NLOPT
    1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_ADD_INEQUALITY_CONSTRAINT referenced in function MOD_NLOPT_mp_SUB_NLOPT
    1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_OPTIMIZE referenced in function MOD_NLOPT_mp_SUB_NLOPT
    1>mod_nlopt.obj : error LNK2019: unresolved external symbol NLO_DESTROY referenced in function MOD_NLOPT_mp_SUB_NLOPT
    
  4. 然后我按照建议[这里](http://nlopt-discuss.ab-initio.mit.narkive.com/M3vzZMYA/nlopt-linked-to-intel-fortran-compiler-for-windows)并将/names:lowercase添加到命令行,现在它编译得很好,但有一个警告:

    libnlopt-0.exp : warning LNK4070: /OUT:libnlopt-0.dll directive in .EXP differs from output filename 'x64\Release\baseline.exe'; ignoring directive
    
  5. 虽然它编译得很好,但我仍然无法运行我的编译代码。当我运行它时,我的计算机告诉我This APP cannot run on your PC. To find a version for your PC, check with the software published。然后命令窗口显示Access denied,然后程序停止。

  6. 我真的不知道接下来我能做些什么来使我的代码工作。我知道有很多人在Windows中使用NLopt。

1 个答案:

答案 0 :(得分:0)

我刚刚想出了解决方案。对于上面的第二步,我只应将“libnlopt-0.lib”,而不是“libnlopt-0.exp”添加到Visual Studio项目属性中的“附加依赖项”。之后,我将“libnlopt-0.dll”复制到我程序的工作目录中。然后我的程序可以运行没有任何问题!