Can't run mex-built application in Ubuntu 18.04
Show older comments
I followed this example to compile a mex application in Ubuntu 18.04. I successfully built engdemo object as shown in the output of mex:
mex -v -client engine engdemo.cpp
Verbose mode is on.
... Looking for compiler 'g++' ...
... Executing command 'which g++' ...Yes ('/usr/bin/g++').
... Executing command 'g++ -print-file-name=libstdc++.so' ...Yes ('/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.so').
... Executing command 'g++ -dumpversion' ...Yes ('7').
... Executing command 'which g++' ...Yes ('/usr/bin/g++').
... Looking for folder '/usr' ...Yes.
... Executing command 'g++ -dumpmachine' ...Yes ('x86_64-linux-gnu').
Found installed compiler 'g++'.
Set INCLUDE = /usr/lib/gcc/x86_64-linux-gnu/7/include;/usr/include/c++/7;/usr/include/c++/7/x86_64-linux-gnu;/usr/include/c++/7/backward;
Options file details
-------------------------------------------------------------------
Compiler location: /usr/bin/g++
Options file: /home/tley7b/.matlab/R2021b/mex_C++_glnxa64.xml
CMDLINE1 : /usr/bin/g++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I"/usr/local/MATLAB/R2021b/extern/include" -I"/usr/local/MATLAB/R2021b/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -O2 -fwrapv -DNDEBUG "/home/tley7b/test_mex/engdemo.cpp" -o /tmp/mex_20753447411181_1313/engdemo.o
CMDLINE2 : /usr/bin/g++ -pthread -Wl,--no-undefined -O /tmp/mex_20753447411181_1313/engdemo.o "/usr/local/MATLAB/R2021b/sys/os/glnxa64/orig/libstdc++.so.6" $MW_GLIBC_SHIM -Wl,--as-needed -Wl,-rpath-link,/usr/local/MATLAB/R2021b/extern/bin/glnxa64 -L"/usr/local/MATLAB/R2021b/extern/bin/glnxa64" -Wl,-rpath-link,/usr/local/MATLAB/R2021b/bin/glnxa64 -L"/usr/local/MATLAB/R2021b/bin/glnxa64" -leng -lMatlabEngine -lMatlabDataArray -lmx -lmat -lm -o engdemo
CXX : /usr/bin/g++
DEFINES : -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
CFLAGS : -fexceptions -fPIC -fno-omit-frame-pointer -pthread
CXXFLAGS : -fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11
INCLUDE : -I"/usr/local/MATLAB/R2021b/extern/include" -I"/usr/local/MATLAB/R2021b/simulink/include"
CXXOPTIMFLAGS : -O2 -fwrapv -DNDEBUG
CXXDEBUGFLAGS : -g
LDXX : /usr/bin/g++
LDFLAGS : -pthread -Wl,--no-undefined
LDTYPE :
LINKEXPORT :
LINKEXPORTVER :
LINKLIBS : "/usr/local/MATLAB/R2021b/sys/os/glnxa64/orig/libstdc++.so.6" $MW_GLIBC_SHIM -Wl,--as-needed -Wl,-rpath-link,/usr/local/MATLAB/R2021b/extern/bin/glnxa64 -L"/usr/local/MATLAB/R2021b/extern/bin/glnxa64" -Wl,-rpath-link,/usr/local/MATLAB/R2021b/bin/glnxa64 -L"/usr/local/MATLAB/R2021b/bin/glnxa64" -leng -lMatlabEngine -lMatlabDataArray -lmx -lmat -lm
LDOPTIMFLAGS : -O
LDDEBUGFLAGS : -g
MWCPPLIB : "/usr/local/MATLAB/R2021b/sys/os/glnxa64/orig/libstdc++.so.6"
OBJEXT : .o
LDEXT :
SETENV : CC="gcc"
CXX="/usr/bin/g++"
CFLAGS="-fexceptions -fPIC -fno-omit-frame-pointer -pthread -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE "
CXXFLAGS="-fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE "
COPTIMFLAGS="-O2 -fwrapv -DNDEBUG"
CXXOPTIMFLAGS="-O2 -fwrapv -DNDEBUG"
CDEBUGFLAGS="-g"
CXXDEBUGFLAGS="-g"
MW_GLIBC_SHIM="$MW_GLIBC_SHIM"
LD="gcc"
LDXX="/usr/bin/g++"
LDFLAGS="-pthread -Wl,--no-undefined "/usr/local/MATLAB/R2021b/sys/os/glnxa64/orig/libstdc++.so.6" $MW_GLIBC_SHIM -Wl,--as-needed -Wl,-rpath-link,/usr/local/MATLAB/R2021b/extern/bin/glnxa64 -L"/usr/local/MATLAB/R2021b/extern/bin/glnxa64" -Wl,-rpath-link,/usr/local/MATLAB/R2021b/bin/glnxa64 -L"/usr/local/MATLAB/R2021b/bin/glnxa64" -leng -lMatlabEngine -lMatlabDataArray -lmx -lmat -lm "
LDDEBUGFLAGS="-g"
GCC : /usr/bin/g++
CPPLIB_DIR : /usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.so
VER : 7
GCCDIR : /usr
GCC_TARGET : x86_64-linux-gnu
MATLABROOT : /usr/local/MATLAB/R2021b
ARCH : glnxa64
SRC : "/home/tley7b/test_mex/engdemo.cpp"
OBJ : /tmp/mex_20753447411181_1313/engdemo.o
OBJS : /tmp/mex_20753447411181_1313/engdemo.o
SRCROOT : /home/tley7b/test_mex/engdemo
DEF : /tmp/mex_20753447411181_1313/engdemo.def
EXP : "engdemo.exp"
LIB : "engdemo.lib"
EXE : engdemo
ILK : "engdemo.ilk"
MANIFEST : "engdemo.manifest"
TEMPNAME : engdemo
EXEDIR :
EXENAME : engdemo
OPTIM : -O2 -fwrapv -DNDEBUG
LINKOPTIM : -O
-------------------------------------------------------------------
Building with 'g++'.
/usr/bin/g++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I"/usr/local/MATLAB/R2021b/extern/include" -I"/usr/local/MATLAB/R2021b/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -O2 -fwrapv -DNDEBUG "/home/tley7b/test_mex/engdemo.cpp" -o /tmp/mex_20753447411181_1313/engdemo.o
/usr/bin/g++ -pthread -Wl,--no-undefined -O /tmp/mex_20753447411181_1313/engdemo.o "/usr/local/MATLAB/R2021b/sys/os/glnxa64/orig/libstdc++.so.6" $MW_GLIBC_SHIM -Wl,--as-needed -Wl,-rpath-link,/usr/local/MATLAB/R2021b/extern/bin/glnxa64 -L"/usr/local/MATLAB/R2021b/extern/bin/glnxa64" -Wl,-rpath-link,/usr/local/MATLAB/R2021b/bin/glnxa64 -L"/usr/local/MATLAB/R2021b/bin/glnxa64" -leng -lMatlabEngine -lMatlabDataArray -lmx -lmat -lm -o engdemo
MEX completed successfully.
I also setup LD_LIBRARY_PATH, PATH and search path correctly. However, I can't get the application to run by calling
./engdemo
The error is
./engdemo
↑
Invalid use of operator.
Any suggestion?
Accepted Answer
More Answers (0)
Categories
Find more on Programming 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!