简体   繁体   English

在Windows cmd提示符下工作时设置NLOpt

[英]Setting up NLOpt when working from windows cmd prompt

I am writing a c++ program from the windows cmd prompt, and compiling with mingw ( g++ ). 我正在从Windows cmd提示符下编写一个c ++程序,并使用mingw( g++ )进行编译。 This program needs a non-linear optimiser and NLOpt looks like a good choice. 该程序需要一个非线性优化器, NLOpt看起来是一个不错的选择。 I learnt c++ for a uni course, so the environment I was using was already set up, I have no experience in setting up libraries etc. 我是为单门课程学习c ++的,所以已经建立了我所使用的环境,我没有建立库等的经验。

So far my steps have been; 到目前为止,我的步骤已经完成;

  1. Download the precompiled DLLs for 64-bit windows (which is what I'm running) from here . 此处下载用于64位Windows(这是我正在运行的)的预编译DLL。

  2. Run the command dlltool --input-def libnlopt-0.def --dllname libnlopt-0.dll --output-lib libnlopt-0.lib (from the same page ), which ran without errors. 运行命令dlltool --input-def libnlopt-0.def --dllname libnlopt-0.dll --output-lib libnlopt-0.lib (在同一页面上 ),该命令没有错误运行。

This creates an .hpp file, however, when I try to #include the file I get 这会创建一个.hpp文件,但是,当我尝试#include该文件时,

In file included from optimiseDogs.cc:9:0:
C:\Files|Development\NLOpt2.4.2\nlopt.hpp:29:19: fatal error: nlopt.h: Nosuch file or directory
#include <nlopt.h>

nlopt.h and nlopt.hpp are in the same directory as each other. nlopt.hnlopt.hpp彼此位于同一目录中。 My program is in a different folder. 我的程序在另一个文件夹中。 文件夹设置的图像

This is probably really basic, sorry to trouble you with it. 这可能真的很基础,很抱歉给您带来麻烦。 Perhaps I am not completely alone in my ignorance and this will help someone else too. 也许我并不完全无知,这也会帮助其他人。 Also, I have seen this question , but it deals with installing on visual basic, and I'm not using a GUI, just notepad++ and the cmd prompt. 另外,我已经看到了这个问题 ,但是它涉及在Visual Basic上进行安装,并且我没有使用GUI,只是notepad ++和cmd提示符。

Thank you for your help. 谢谢您的帮助。

If you are in windows and using mingw : downloaded zip archive already contains .dll and .lib files. 如果您在windows并使用mingw :下载的zip存档已包含.dll.lib文件。 So you dont need to run dlltool which creates these .lib , .dll from .def . 因此,您无需运行dlltool.def创建这些.lib.dll I think your problem is compiling command using g++ adding include and library path directives. 我认为您的问题是使用g++添加包含和库路径指令来编译命令。

C:\Files\Development\NLOpt2.4.2>g++ <path_of_source>.cc -o program.exe -L. -lnlopt -lm -I. -I<path_of_your_headers>

I encounted in the past that order of -I and -L may matter so try changing if not working. 过去我曾说过-I-L顺序可能很重要,因此如果不起作用,请尝试更改。 Please see this tut and that tut to understand the concept. 请参阅此Tut该Tut以了解概念。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM