Why do I get a runtime error when I try to link against multiple Compiler generated libraries that link against the Graphics library?

1 view (last 30 days)
I get a runtime error when I try to link against multiple Compiler generated libraries that links against the Graphics library. I am using MATLAB 6.1 and the MATLAB C/C++ Graphics Library 2.3 (R12.1+).
I produced the libraries using the following command in MATLAB:
mcc -t -L C -W libhg:mylib -T link:lib -h test.m libmmfile.mlib
In my main file, I initialze and terminate my libraries like this:
void main(int argc, char **argv)
{
InitializeLib1();
... /*call lib1 functions*/
TerminateLib1();
InitializeLib2();
... /*call lib2 functions*/
TerminateLib2();
}
When I run this application, I get the following error at runtime:
There can BE only ONE root object.
EXITING

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The MATLAB C/C++ Graphics Library has not been fully tested for use in a MATLAB Compiler generated shared library. Also, using the Graphics Library in a shared library is not officially supported by MathWorks. The MATLAB C/C++ Graphics Library is only supported for use in MATLAB Compiler generated executables.
To work around this issue, initalize both shared libraries at the beginning of your application and terminate them both at the end. The order is shown in the pseudocode below:
void main(int argc, char **argv)
{
InitializeLib1();
InitializeLib2();
... /*call lib1 and lib2 functions*/
TerminateLib2();
TerminateLib1();
}
For more information on how to link against a MATLAB Compiler generated shared library using Microsoft Visual Studio, refer to the Related Solution at the bottom of the page.

More Answers (0)

Categories

Find more on C Shared Library Integration 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!