Why do I receive unresolved symbol errors when trying to compile my MATLAB function using graphics?

2 ビュー (過去 30 日間)
I am trying to compile the following function:
function test_graphics_mcc( power )
x=-10:.1:10;
y=x.^power;
plot(x,y);
title(sprintf('x^%i',power));
xlabel('x');
ylabel('y');
I then compile it with the command:
mcc -t -L C -W libhg:test_graphics_mcclib -T link:lib test_graphics_mcc.m libmmfile.mlib libmwsglm.mlib
I receive the following errors: ERROR: test_graphics_mcc.obj .text: undefined reference to '_mlfNTitle' test_graphics_mcc.obj .text: undefined reference to '_mlfNXlabel' test_graphics_mcc.obj .text: undefined reference to '_mlfNYlabel'
MBUILD.BAT: Error: Link of 'test_graphics_mcclib.dll' failed.
??? Error using ==> mbuild
Unable to complete successfully
??? Error: An error occurred while shelling out to mbuild (error code = 1).
Unable to build executable (specify the -v option for more information).
Error in ==> C:\MATLAB6p5\toolbox\compiler\mcc.dll

採用された回答

MathWorks Support Team
MathWorks Support Team 2018 年 6 月 14 日
Using graphics in shared libraries is not supported.
The "-T link:lib" is what tells MCC to generate a shared library. You should generate only stand alone executables using graphics.
However, the actual error displayed is due to using Handle Graphics and a missing switch to MCC. Since you are using Handle Graphics, you need to use the "-B sgl" switch.
For more information, see:
If you have already installed the help documentation for your licensed product(s), you may access the same page locally by typing the following at the MATLAB prompt:
web([docroot '/toolbox/compiler/mcc.html'])
From there:
-B sgl (Stand-Alone C Graphics Library).
Produce a stand-alone C application that uses Handle Graphics. The -B sgl option is equivalent to the series of options -m -W mainhg libmwsglm.mlib
Here is the full command you should use:
mcc -B sgl -t -L C -W libhg:test_graphics_mcclib -T link:lib test_graphics_mcc.m libmmfile.mlib
However, remember that this is not supported, and you may run into other problems at a later time.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeC Shared Library Integration についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by