Help me compile NLOPT and its associated Matlab plugin on Windows
July 22, 2020 4:34 PM   Subscribe

Deep sigh. I have spent the day trying to stretch my understanding of how to download and compile source code and then compile the appropriate MEX file, and I've decided I'm out of my depth because I don't actually know how C works. Please walk me through what I need to do to actually get this working on Windows! (gory details inside)

I'm asking here instead of Stack Overflow because I don't know enough to ask precisely enough to not worry about getting yelled at over there. I realize this question is highly specific but I'm hoping that someone who has more of a CS or technical computing background and can translate a bit to help me figure out what I'm missing here.

So: I'm on Windows 10, and trying to install NLOPT, a library for numerical optimization that allegedly plays nicely with Matlab. I don't know C, really, and I'm pretty unused to compiling stuff, so here's what I'm trying and tell me where I'm going wrong:

Using Visual Studio, I cloned the git repository, built the CMake stuff, and installed it. The end result is a directory with a bunch of subdirectories that look promising (one includes nlopt.h, another includes a bunch of matlab files that look right...) I download the suggested mex file and try to compile it in Matlab (in the same subdirectory as directory as nlopt.h; otherwise it complains that it can't find nlopt.h). The end result is a list of 24 "unresolved externals" (here's a pastebin)

So googling is suggesting that when Matlab tries to compile the c code, it's seeing functions declared without those things being actually defined anywhere. I assume that they are supposed to be defined somewhere in the compiled stuff but I don't know where to point Matlab to or how to point it. OR, If this suggests I screwed up some earlier step and some stuff didn't get created or what. Any hints as to where I should try to track things down? Running Matlab 2020a Update 1, if that matters?

Happy to clarify or check anything that would be helpful. I'm just somewhat out of my depth so I don't know if there's something obvious I should have done (or if I'm saying anything wrong or silly).
posted by dismas to Computers & Internet (3 answers total) 1 user marked this as a favorite
 
Best answer: Here's what seems to be happening:

Building Nlopt should cause a DLL with a name like nlopt.dll to be created. This contains the compiled code for the nlopt library. When building the mex file, you need to tell the compiler what directory contains nlopt.dll. The errors are because the compiler can't find the DLL.

I'm on my phone, so I can't help with detailed compiler options.
posted by monotreme at 4:53 PM on July 22, 2020 [2 favorites]


Response by poster: UGH thanks, that seemed to do it. I moved both the nlopt.lib and nlopt.dll files that were created when I compiled, and then including them using -lnlopt option seemed to do it. Swore I tried that before, but it compiled successfully!
posted by dismas at 5:03 PM on July 22, 2020 [1 favorite]


Best answer: In general you don't want to manually move files around. If a .c file needs includes, you give it the path with -I, and if it needs libraries you give it the path with -L. Moving things around makes it hard to change things in the future. Takes a bit more work up front, to be sure.
posted by wnissen at 5:42 PM on July 22, 2020 [1 favorite]


« Older sign on empty apartment building - what is it?   |   Help me wrap my head around buying a car [in... Newer »
This thread is closed to new comments.