Error in compiled application, constant property can't be found

1 次查看(过去 30 天)
I compiled a standalone executable using the Application Compiler but get an error when starting it because of 'Unable to resolve the name TestHelperClass.TestString'. Matlab then throws this error: MATLAB:undefinedVarOrClass. The TestHelperClass looks like this:
classdef TestHelperClass
properties (Constant)
TestString = "test"
end
end
When using this way of getting predefined strings in MATLAB it works fine but not in compiled executables. Using get-functions which return the same strings results in the exact same error so sadly this doesn't work.
Is there a workaround for this error?
  2 个评论
dpb
dpb 2025-8-28
Did the compiler include the m-file containing the class definition in the required files?
Simeon
Simeon 2025-8-29

Yes it did, tried it with a different one which I added manually but still doesn’t work.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2025-8-29
You need to create an object of class TestHelperClass and access the TestString property of that object.
Unfortunately it is not possible to subclass string class in order to hypthetically create an enumeration of type string.
  2 个评论
Simeon
Simeon 2025-8-29
I added a basic constructor like this:
methods
function obj = TestHelperClass()
end
end
But now I get this error 'MATLAB:scriptNotAFunction' when calling it like this:
testHelpObj = TestHelperClass;
And also for this:
testHelpObj = TestHelperClass();
Walter Roberson
Walter Roberson 2025-8-29
file TestHelperClass.m
classdef TestHelperClass
properties (Constant)
TestString = "test";
end
methods
function obj = TestHelperClass()
end
end
end
together with separate
testHelpObj = TestHelperClass;
testHelpObj.TestString
However, you do not need the constructor in this particular case. It works to use file TestHelperClass.m
classdef TestHelperClass
properties (Constant)
TestString = "test";
end
end
The seperate assignment to testHelpObj must not be part of TestHelperClass.m

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by