Setting up NLOpt when working from windows cmd prompt

1.4k Views Asked by At

I am writing a c++ program from the windows cmd prompt, and compiling with mingw (g++). This program needs a non-linear optimiser and NLOpt looks like a good choice. 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.

So far my steps have been;

  1. Download the precompiled DLLs for 64-bit windows (which is what I'm running) from here.

  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.

This creates an .hpp file, however, when I try to #include the file I get

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. My program is in a different folder. image of folder setup

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.

Thank you for your help.

1

There are 1 best solutions below

2
On BEST ANSWER

If you are in windows and using mingw: downloaded zip archive already contains .dll and .lib files. So you dont need to run dlltool which creates these .lib,.dll from .def. I think your problem is compiling command using g++ adding include and library path directives.

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. Please see this tut and that tut to understand the concept.