2017-04-08 275 views
0

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

这里是我做了什么,而我所遇到的问题:

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

  2. 我在Visual Studio中创建了一个Fortran项目,并使用在Linux下工作的代码。在Visual Studio中,我将.lib和.exp的路径添加到项目属性的“Additional Include Directories”和“Additional Library Directories”。我还将“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,然后程序停止。

我真的不知道我可以在旁边做什么使我的代码工作。我知道有很多人在Windows中使用NLopt。

+0

你有哪个Windows版本?它是64位吗?你的编译命令是怎样的? –

+0

我正在使用64位版本的Windows 10.编译是由Visuao Studio使用标准编译选项完成的,除了上面提到的'/ names:lowercase'选项。 –

回答

0

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

相关问题