引擎 Matlab 问题

Posted

技术标签:

【中文标题】引擎 Matlab 问题【英文标题】:Engine Matlab issues 【发布时间】:2010-02-23 16:42:05 【问题描述】:

我正在尝试在 C++ 程序中实现 Matlab。 http://www.cl.cam.ac.uk/~sjeh3/wii/ 该应用程序使用 gtk a wii mote lib 和 Matlab Camera Calibration Toolbox (http://www.vision.caltech.edu/bouguetj/calib_doc/)。它完美地工作。 我想使用 matlab 绘图工具来构建应用程序提供的图形。但我在使用 matlab 引擎构建应用程序时遇到问题。

在 main.cpp 中,我只是在 main 函数中添加了 matlab 示例 engdemo.cpp 中的代码,并包含了 engine.h 和 mex.h。 即使有像 engdemo.cpp 这样的例子,我总是有这个错误:

mex:“...mexa64”的链接失败。

这里是控制台视图:

    root@ubuntu:/home/hugo/Bureau/sjeh3-wii/wmgui# ./build2
----------------------------------------------------------------
-> mbuildopts.sh sourced from directory (DIR = $HOME/.matlab/$REL_VERSION)
   FILE = /root/.matlab/R2009b/mbuildopts.sh
----------------------------------------------------------------
->    TMW_ROOT              = /home/hugo/Matlab
->    CC                    = g++-4.1
->    CC flags:
         CFLAGS             = -ansi -D_GNU_SOURCE -I/home/hugo/Matlab/extern/include/cpp -I/home/hugo/Matlab/extern/include -DUNIX -DX11 -DGLNXA64 -DGCC -pthread
         CDEBUGFLAGS        = -g
         COPTIMFLAGS        = -O -DNDEBUG
         CLIBS              = -Wl,-rpath-link,/home/hugo/Matlab/bin/glnxa64 -L/home/hugo/Matlab/runtime/glnxa64  -lmwmclmcrrt -lm
         arguments          = 
->    LD                    = g++-4.1
->    Link flags:
         LDFLAGS            = -pthread
         LDDEBUGFLAGS       = -g
         LDOPTIMFLAGS       = -O
         arguments          =  -L/usr/lib/ -L../toolbox -L../libcwiid -L../libcwiid -L/opt/gnome/lib64 -L/home/hugo/Matlab/bin/glnxa64 -L/home/hugo/Matlab/extern/include -L../../matlablibtest/toolbox
----------------------------------------------------------------

-> g++-4.1 -c  -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/libpng12 -I/opt/gnome/include/gtk-2.0 -I/usr/include/gtk-2.0 -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/gtk-2.0/include -I../libcwiid -I../toolbox -I/opt/matlab/extern/include -I/usr/lib -I/home/hugo/Matlab/extern/include -I/home/hugo/Matlab/bin/glnxa64 -ansi -D_GNU_SOURCE -I/home/hugo/Matlab/extern/include/cpp -I/home/hugo/Matlab/extern/include -DUNIX -DX11 -DGLNXA64 -DGCC -pthread  -g  "main.cpp"

-> g++-4.1 -c  -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/libpng12 -I/opt/gnome/include/gtk-2.0 -I/usr/include/gtk-2.0 -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/gtk-2.0/include -I../libcwiid -I../toolbox -I/opt/matlab/extern/include -I/usr/lib -I/home/hugo/Matlab/extern/include -I/home/hugo/Matlab/bin/glnxa64 -ansi -D_GNU_SOURCE -I/home/hugo/Matlab/extern/include/cpp -I/home/hugo/Matlab/extern/include -DUNIX -DX11 -DGLNXA64 -DGCC -pthread  -g  "interface.cpp"

-> g++-4.1 -c  -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/libpng12 -I/opt/gnome/include/gtk-2.0 -I/usr/include/gtk-2.0 -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/gtk-2.0/include -I../libcwiid -I../toolbox -I/opt/matlab/extern/include -I/usr/lib -I/home/hugo/Matlab/extern/include -I/home/hugo/Matlab/bin/glnxa64 -ansi -D_GNU_SOURCE -I/home/hugo/Matlab/extern/include/cpp -I/home/hugo/Matlab/extern/include -DUNIX -DX11 -DGLNXA64 -DGCC -pthread  -g  "support.cpp"

-> g++-4.1 -g -pthread  -L/usr/lib/ -L../toolbox -L../libcwiid -L../libcwiid -L/opt/gnome/lib64 -L/home/hugo/Matlab/bin/glnxa64 -L/home/hugo/Matlab/extern/include -L../../matlablibtest/toolbox -o wmgui  main.o interface.o support.o -Wl,-rpath-link,/home/hugo/Matlab/bin/glnxa64 -L/home/hugo/Matlab/runtime/glnxa64  -lmwmclmcrrt -lm  -lcalib -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lfreetype -lz -lfontconfig -lexpat -lglitz -lm -lpng12 -lXrender -lX11 -lpthread -lXau -lXdmcp -lgthread-2.0 -lglib-2.0 -lm -lcwiid

main.o: In function `main':
/home/hugo/Bureau/sjeh3-wii/wmgui/main.cpp:363: undefined reference to `engOpen'
/home/hugo/Bureau/sjeh3-wii/wmgui/main.cpp:367: undefined reference to `engEvalString'
collect2: ld returned 1 exit status

    mbuild: link of 'wmgui' failed.

root@ubuntu:/home/hugo/Bureau/sjeh3-wii/wmgui# ./build2
-> mexopts.sh sourced from directory (DIR = $HOME/.matlab/$REL_VERSION)
   FILE = /root/.matlab/R2009b/mexopts.sh
----------------------------------------------------------------
->    MATLAB                = /home/hugo/Matlab
->    CC                    = gcc-4.1
->    CC flags:
         CFLAGS             = -ansi -D_GNU_SOURCE  -fexceptions -fPIC -fno-omit-frame-pointer -pthread
         CDEBUGFLAGS        = -g
         COPTIMFLAGS        = -O -DNDEBUG
         CLIBS              = -Wl,-rpath-link,/home/hugo/Matlab/bin/glnxa64 -L/home/hugo/Matlab/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
         arguments          =  -DMX_COMPAT_32
->    CXX                   = g++-4.1
->    CXX flags:
         CXXFLAGS           = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
         CXXDEBUGFLAGS      = -g
         CXXOPTIMFLAGS      = -O -DNDEBUG
         CXXLIBS            = -Wl,-rpath-link,/home/hugo/Matlab/bin/glnxa64 -L/home/hugo/Matlab/bin/glnxa64 -lmx -lmex -lmat -lm
         arguments          =  -DMX_COMPAT_32
->    FC                    = g95
->    FC flags:
         FFLAGS             = -fexceptions -fPIC -fno-omit-frame-pointer
         FDEBUGFLAGS        = -g
         FOPTIMFLAGS        = -O
         FLIBS              = -Wl,-rpath-link,/home/hugo/Matlab/bin/glnxa64 -L/home/hugo/Matlab/bin/glnxa64 -lmx -lmex -lmat -lm
         arguments          =  -DMX_COMPAT_32
->    LD                    = g++-4.1
->    Link flags:
         LDFLAGS            = -pthread -shared -Wl,--version-script,/home/hugo/Matlab/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined
         LDDEBUGFLAGS       = -g
         LDOPTIMFLAGS       = -O
         LDEXTENSION        = .mexa64
         arguments          =  -lang cpp -L/usr/lib/ -L../toolbox -L../libcwiid -lcalib -L../libcwiid -L/opt/gnome/lib64 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lfreetype -lz -lfontconfig -lexpat -lglitz -lm -lpng12 -lXrender -lX11 -lpthread -lXau -lXdmcp -lgthread-2.0 -lglib-2.0 -lm -lcwiid -L/home/hugo/Matlab/bin/glnxa64 -L/home/hugo/Matlab/extern/include -L../../matlablibtest/toolbox
->    LDCXX                 = 
->    Link flags:
         LDCXXFLAGS         = 
         LDCXXDEBUGFLAGS    = 
         LDCXXOPTIMFLAGS    = 
         LDCXXEXTENSION     = 
         arguments          =  -lang cpp -L/usr/lib/ -L../toolbox -L../libcwiid -lcalib -L../libcwiid -L/opt/gnome/lib64 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lfreetype -lz -lfontconfig -lexpat -lglitz -lm -lpng12 -lXrender -lX11 -lpthread -lXau -lXdmcp -lgthread-2.0 -lglib-2.0 -lm -lcwiid -L/home/hugo/Matlab/bin/glnxa64 -L/home/hugo/Matlab/extern/include -L../../matlablibtest/toolbox
----------------------------------------------------------------

-> g++-4.1 -c  -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/libpng12 -I/opt/gnome/include/gtk-2.0 -I/usr/include/gtk-2.0 -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/gtk-2.0/include -I../libcwiid -I../toolbox -I/opt/matlab/extern/include -I/usr/lib -I/home/hugo/Matlab/extern/include -I/home/hugo/Matlab/bin/glnxa64 -I/home/hugo/Matlab/extern/include -I/home/hugo/Matlab/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread  -DMX_COMPAT_32 -g  "main.cpp"

-> g++-4.1 -c  -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/libpng12 -I/opt/gnome/include/gtk-2.0 -I/usr/include/gtk-2.0 -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/gtk-2.0/include -I../libcwiid -I../toolbox -I/opt/matlab/extern/include -I/usr/lib -I/home/hugo/Matlab/extern/include -I/home/hugo/Matlab/bin/glnxa64 -I/home/hugo/Matlab/extern/include -I/home/hugo/Matlab/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread  -DMX_COMPAT_32 -g  "interface.cpp"

-> g++-4.1 -c  -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/libpng12 -I/opt/gnome/include/gtk-2.0 -I/usr/include/gtk-2.0 -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/gtk-2.0/include -I../libcwiid -I../toolbox -I/opt/matlab/extern/include -I/usr/lib -I/home/hugo/Matlab/extern/include -I/home/hugo/Matlab/bin/glnxa64 -I/home/hugo/Matlab/extern/include -I/home/hugo/Matlab/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread  -DMX_COMPAT_32 -g  "support.cpp"

-> g++-4.1 -g -pthread -shared -Wl,--version-script,/home/hugo/Matlab/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -o  "wmgui.mexa64"  main.o interface.o support.o  -lang cpp -L/usr/lib/ -L../toolbox -L../libcwiid -lcalib -L../libcwiid -L/opt/gnome/lib64 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lfreetype -lz -lfontconfig -lexpat -lglitz -lm -lpng12 -lXrender -lX11 -lpthread -lXau -lXdmcp -lgthread-2.0 -lglib-2.0 -lm -lcwiid -L/home/hugo/Matlab/bin/glnxa64 -L/home/hugo/Matlab/extern/include -L../../matlablibtest/toolbox -Wl,-rpath-link,/home/hugo/Matlab/bin/glnxa64 -L/home/hugo/Matlab/bin/glnxa64 -lmx -lmex -lmat -lm

g++-4.1: cpp: Aucun fichier ou dossier de ce type

    mex: link of ' "wmgui.mexa64"' failed.


#!/bin/sh
(mex or mbuild) -v -g -output wmgui main.cpp interface.cpp support.cpp -lang cpp \
-L/usr/lib/ -L../toolbox -L../libcwiid -lcalib -L../libcwiid -L/opt/gnome/lib64 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lfreetype -lz -lfontconfig -lexpat -lglitz -lm -lpng12 -lXrender -lX11 -lpthread -lXau -lXdmcp -lgthread-2.0 -lglib-2.0 -lm -lcwiid -L/home/hugo/Matlab/bin/glnxa64 -L/home/hugo/Matlab/extern/include -L../../matlablibtest/toolbox \
-I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/libpng12 -I/opt/gnome/include/gtk-2.0 -I/usr/include/gtk-2.0 -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/gtk-2.0/include  -I../libcwiid -I../toolbox -I/opt/matlab/extern/include -I/usr/lib -I/home/hugo/Matlab/extern/include -I/home/hugo/Matlab/bin/glnxa64

我忘了说我想使用 Matlab 引擎而不是我在 matlab 中的 c++ 应用程序。也许不是那么清楚。我认为该程序不会作为 mex 文件运行。

真诚地, 雨果

【问题讨论】:

【参考方案1】:

如果发现我的问题。我正在使用 mexopts.sh conf 而不是 engopts.sh 编译我的应用程序 成功编译后,我有错误无法启动 Matlab 引擎。我只是 apt-get 安装 csh。并且有效。

【讨论】:

【参考方案2】:

您的 linux 构建命令已损坏。编译器缺少某些库的一些路径。

    #!/bin/sh
(mex or mbuild) -v -g -output wmgui main.cpp interface.cpp support.cpp -lang cpp \
-L/usr/lib/ -L../toolbox -L../libcwiid -lcalib -L../libcwiid -L/opt/gnome/lib64 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lfreetype -lz -lfontconfig -lexpat -lglitz -lm -lpng12 -lXrender -lX11 -lpthread -lXau -lXdmcp -lgthread-2.0 -lglib-2.0 -lm -lcwiid -L/home/hugo/Matlab/bin/glnxa64 -L/home/hugo/Matlab/extern/include -L../../matlablibtest/toolbox \
-I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/libpng12 -I/opt/gnome/include/gtk-2.0 -I/usr/include/gtk-2.0 -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/gtk-2.0/include  -I../libcwiid -I../toolbox -I/opt/matlab/extern/include -I/usr/lib -I/home/hugo/Matlab/extern/include -I/home/hugo/Matlab/bin/glnxa64

通常你应该在这行代码中找到你的答案!

真诚的 雨果

【讨论】:

以上是关于引擎 Matlab 问题的主要内容,如果未能解决你的问题,请参考以下文章

C中的Matlab引擎函数返回零

如何调试 Matlab 引擎 C API?

加速 Matlab 引擎调用

如何在从 Matlab 调用的 mex 函数中使用 Matlab 引擎

QT调用matlab引擎提示无法解析的外部符号

实践Matlab R2016a使用MDCE引擎建立集群