mex error. undefined reference
119 views (last 30 days)
Show older comments
I was trying to use NLOPT ( https://nlopt.readthedocs.io/en/latest/ ) on Matlab (Windows system) following the instruction https://nlopt.readthedocs.io/en/latest/NLopt_on_Windows/.After generating the lib file from dll, I tried
mex -v nlopt_optimize.c libnlopt-0.lib
and got the error message
Verbose mode is on.
Neither -compatibleArrayDims nor -largeArrayDims is selected.
Using -compatibleArrayDims. In the future, MATLAB will require the use of
-largeArrayDims and remove the -compatibleArrayDims option.
For more information:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
... Looking for compiler 'MinGW64 Compiler (C)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9').
... Looking for file 'C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\bin\gcc.exe' ...Yes.
... Looking for folder 'C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9' ...Yes.
Found installed compiler 'MinGW64 Compiler (C)'.
Set PATH = C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\bin;C:\Program Files\MATLAB\R2016a\extern\include\win64;C:\Program Files\MATLAB\R2016a\extern\include;C:\Program Files\MATLAB\R2016a\simulink\include;C:\Program Files\MATLAB\R2016a\lib\win64;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files\Microsoft MPI\Bin\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\RSoft\bin;C:\RSoft\bin32;C:\Program Files\MATLAB\R2016a\runtime\win64;C:\Program Files\MATLAB\R2016a\bin;C:\Program Files\MATLAB\R2013b\runtime\win64;C:\Program Files\MATLAB\R2013b\bin;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\dotnet\
Set INCLUDE = C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\include;;C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\include;;
Set LIB = C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\lib;;C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\lib;;
Set MW_TARGET_ARCH = win64;win64;
Set LIBPATH = C:\Program Files\MATLAB\R2016a\extern\lib\win64;C:\Program Files\MATLAB\R2016a\extern\lib\win64;
Options file details
-------------------------------------------------------------------
Compiler location: C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9
Options file: C:\Users\Jaewon\AppData\Roaming\MathWorks\MATLAB\R2016a\mex_C_win64.xml
CMDLINE1 : C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\bin\gcc -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"C:\Program Files\MATLAB\R2016a/extern/include" -I"C:\Program Files\MATLAB\R2016a/simulink/include" -I"C:\Program Files\MATLAB\R2016a/extern\lib\win64\mingw64" -fexceptions -fno-omit-frame-pointer -O -DNDEBUG C:\nlopt-2.4.2-dll64\nlopt_optimize.c -o C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj
CMDLINE2 : C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\bin\gcc -m64 -Wl,--no-undefined -shared -s -Wl,"C:\Program Files\MATLAB\R2016a/extern/lib/win64/mingw64/mexFunction.def" C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj libnlopt-0.lib -L"C:\Program Files\MATLAB\R2016a\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -o nlopt_optimize.mexw64
CC : C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\bin\gcc
COMPILER : C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\bin\gcc
DEFINES : -DMX_COMPAT_32 -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
CFLAGS : -fexceptions -fno-omit-frame-pointer
INCLUDE : -I"C:\Program Files\MATLAB\R2016a/extern/include" -I"C:\Program Files\MATLAB\R2016a/simulink/include" -I"C:\Program Files\MATLAB\R2016a/extern\lib\win64\mingw64"
COPTIMFLAGS : -O -DNDEBUG
CDEBUGFLAGS : -g
LD : C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\bin\gcc
LINKER : C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\bin\gcc
LDTYPE : -shared
LDFLAGS : -m64 -Wl,--no-undefined
LINKEXPORT : -Wl,"C:\Program Files\MATLAB\R2016a/extern/lib/win64/mingw64/mexFunction.def"
LIBLOC : C:\Program Files\MATLAB\R2016a\extern\lib\win64\mingw64
LINKLIBS : libnlopt-0.lib -L"C:\Program Files\MATLAB\R2016a\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas
LDOPTIMFLAGS : -s
LDDEBUGFLAGS : -g
OBJEXT : .obj
LDEXT : .mexw64
SETENV : set COMPILER=gcc
set COMPFLAGS=-c -fexceptions -fno-omit-frame-pointer -DMX_COMPAT_32 -DMATLAB_MEX_FILE -DMATLAB_MEX_FILE
set OPTIMFLAGS=-O -DNDEBUG
set DEBUGFLAGS=-g
set LINKER=gcc
set LINKFLAGS=-m64 -Wl,--no-undefined -shared libnlopt-0.lib -L"C:\Program Files\MATLAB\R2016a\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -Wl,"C:\Program Files\MATLAB\R2016a/extern/lib/win64/mingw64/mexFunction.def"
set LINKDEBUGFLAGS=-g
set NAME_OUTPUT=-o "%OUTDIR%%MEX_NAME%%MEX_EXT%"
MINGWROOT : C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9
MATLABROOT : C:\Program Files\MATLAB\R2016a
ARCH : win64
SRC : C:\nlopt-2.4.2-dll64\nlopt_optimize.c
OBJ : C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj
OBJS : C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj
SRCROOT : C:\nlopt-2.4.2-dll64\nlopt_optimize
DEF : C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.def
EXP : nlopt_optimize.exp
LIB : nlopt_optimize.lib
EXE : nlopt_optimize.mexw64
ILK : nlopt_optimize.ilk
MANIFEST : nlopt_optimize.mexw64.manifest
TEMPNAME : nlopt_optimize
EXEDIR :
EXENAME : nlopt_optimize
OPTIM : -O -DNDEBUG
LINKOPTIM : -s
-------------------------------------------------------------------
Building with 'MinGW64 Compiler (C)'.
C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\bin\gcc -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"C:\Program Files\MATLAB\R2016a/extern/include" -I"C:\Program Files\MATLAB\R2016a/simulink/include" -I"C:\Program Files\MATLAB\R2016a/extern\lib\win64\mingw64" -fexceptions -fno-omit-frame-pointer -O -DNDEBUG C:\nlopt-2.4.2-dll64\nlopt_optimize.c -o C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj
C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\bin\gcc -m64 -Wl,--no-undefined -shared -s -Wl,"C:\Program Files\MATLAB\R2016a/extern/lib/win64/mingw64/mexFunction.def" C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj libnlopt-0.lib -L"C:\Program Files\MATLAB\R2016a\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -o nlopt_optimize.mexw64
Error using mex
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x4df):
undefined reference to `__imp_nlopt_force_stop'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x53e):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x576):
undefined reference to `__imp_nlopt_create'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x59b):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x625):
undefined reference to `__imp_nlopt_set_xtol_abs'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x667):
undefined reference to `__imp_nlopt_set_maxeval'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x687):
undefined reference to `__imp_nlopt_set_maxtime'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x6a8):
undefined reference to `__imp_nlopt_set_population'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x6c9):
undefined reference to `__imp_nlopt_set_vector_storage'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x70a):
undefined reference to `__imp_nlopt_set_initial_step'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x75c):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x79f):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x7ca):
undefined reference to `__imp_nlopt_set_local_optimizer'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x7d3):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x804):
undefined reference to `__imp_nlopt_set_lower_bounds'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x835):
undefined reference to `__imp_nlopt_set_lower_bounds'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x859):
undefined reference to `__imp_nlopt_set_upper_bounds'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x87d):
undefined reference to `__imp_nlopt_set_stopval'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x89d):
undefined reference to `__imp_nlopt_set_ftol_rel'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x8bd):
undefined reference to `__imp_nlopt_set_ftol_abs'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x8dd):
undefined reference to `__imp_nlopt_set_xtol_rel'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x903):
undefined reference to `__imp_nlopt_set_upper_bounds'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x927):
undefined reference to `__imp_nlopt_set_stopval'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x947):
undefined reference to `__imp_nlopt_set_ftol_rel'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x967):
undefined reference to `__imp_nlopt_set_ftol_abs'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x987):
undefined reference to `__imp_nlopt_set_xtol_rel'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x9fa):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0xa32):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0xa95):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0xafd):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0xb85):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0xbd3):
more undefined references to `__imp_nlopt_destroy' follow
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0xdb8):
undefined reference to `__imp_nlopt_set_precond_min_objective'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0xdd8):
undefined reference to `__imp_nlopt_set_precond_max_objective'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0xe0d):
undefined reference to `__imp_nlopt_set_min_objective'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0xe26):
undefined reference to `__imp_nlopt_set_max_objective'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0xe78):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0xee4):
undefined reference to `__imp_nlopt_add_inequality_constraint'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0xf34):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0xf80):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x104e):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x10c6):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x1132):
undefined reference to `__imp_nlopt_add_equality_constraint'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x1181):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x11cc):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x1299):
undefined reference to `__imp_nlopt_destroy'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x1319):
undefined reference to `__imp_nlopt_optimize'
C:\Users\Jaewon\AppData\Local\Temp\mex_17125547961730431_276308\nlopt_optimize.obj:nlopt_optimize.c:(.text+0x1365):
undefined reference to `__imp_nlopt_destroy'
collect2.exe: error: ld returned 1 exit status
I'm pretty sure that all the files are in the same folder, and have no idea what was happening. I would really appreciate it if anyone can help. THX.
(I use MinGW64 as the Compiler (C). )
1 Comment
Walter Cañedo Riedel
on 10 Jul 2020
Hi Zhujun,
If you've solved the problem, would you mind sharing the file?
Thanks
Answers (2)
Dennis Gardner
on 15 Jan 2019
I had the same error, but here is what I did to build successfully on 64 bit Windows 10 machine.
- I downloaded the 64bit version of the zip file from https://nlopt.readthedocs.io/en/latest/NLopt_on_Windows/
- After it downloaded, I unzipped to C:\Users\someFilePath\nlopt
- I opened "Developer Command Prompt for VS 2017" and I changed the directory to C:\Users\someFilePath\nlopt
- In the command prompt, I ran this code:
lib /def:libnlopt-0.def /machine:x64
- The command above created a libnlopt-0.lib file.
- Then I successfully built using the follwing lines of MATLAB code:
% chage directory
cd('C:\Users\someFilePath\nlopt');
% add the files to the search directory
addpath(genpath('C:\Users\someFilePath\nlopt'));
% build, link to header and link to .lib file (no space between -I, -L, and -l)
mex .\matlab\nlopt_optimize.c -IC:\Users\someFilePath\nlopt -LC:\Users\someFilePath\nlopt -llibnlopt-0
0 Comments
James Tursa
on 31 Jan 2018
Unless all of the source C files are explicitly #include in your nlopt_optimize.c file, you must list them explicitly in the mex command. E.g., if there are multiple C source files you would need to do this:
mex -v nlopt_optimize.c another_source1.c another_source2.c libnlopt-0.lib
That is, if another_source1.c and another_source2.c are needed but not explicitly #include in the nlopt_optimize.c file, you have to list them manually in the mex command.
See Also
Categories
Find more on MATLAB Support for MinGW-w64 C/C++ Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!