Error using build after clibgen.generateLibraryDefinition runs as expected.
6 views (last 30 days)
Show older comments
I'm attempting to follow a tutorial for interfacing with C++ libraries in MATLAB. The only major difference between my situation and the author's is that I'm working on a windows machine, meaning that I run
> cl /c rectangle.cpp
> lib /OUT:rectangle.lib rectangle.obj
to compile into a .obj file (rather than .o) and reformat it to .lib. Then, in the MATLAB environment, I run
>> headerFile = "C:\path\to\rectangle.h";
>> libFile = "C:\path\to\rectangle.lib";
>> libName = "rectangle";
>> clibgen.generateLibraryDefinition(headerFile, "Libraries", libFile, "PackageName", libName)
This runs without issue. The generated definerectangle.m looks as I expect, and the summary looks as follows:
>> summary(definerectangle)
MATLAB Interface to rectangle Library
Class clib.rectangle.Rectangle
Constructors:
clib.rectangle.Rectangle(double,double,double,double)
clib.rectangle.Rectangle(clib.rectangle.Rectangle)
Methods:
double Area()
No Properties defined
which seems right. However, when I attempt to build, I get the following result
>> build(definerectangle)
Building interface file 'rectangleInterface.dll' for clib interface 'rectangle'.
Not enough input arguments.
Error in clibgen.internal.build>delAdditionalFiles (line 1001)
for ind = 1:length(cmdFilesList)
^^^^^^^^^^^^
Error in clibgen.internal.build (line 378)
delAdditionalFiles(outputDir, srcFileName, dataFileName, buildExecutable, sourceFilesObj, '');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in clibgen.internal.buildHelper (line 104)
[status,cmdOut] = clibgen.internal.build(srcFile,cellstr(libraries),cellstr(srcFiles),cellstr(includePath),interfaceDir,obj.DefinedMacros,obj.UndefinedMacros, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in clibgen.LibraryDefinition/build (line 1664)
clibgen.internal.buildHelper(obj, obj.LibraryInterface, '', directBuild);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I have checked the mex compiler configuration to see if that might be an issue, but it appears to match what I used to compile with cl.exe
>> mex -setup cpp
MEX configured to use 'Microsoft Visual C++ 2022' for C++ language compilation.
I'm at a loss for what this error could mean, so I would appreciate any help in interpreting it and getting this to work.
0 Comments
Accepted Answer
埃博拉酱
on 25 Jan 2025
Edited: 埃博拉酱
on 26 Jan 2025
Since you didn't provide the source code, I can't reproduce your issue. But I would suggest that you compile a C++ MEX file function instead of using clibgen. MEX is generally less error-prone and performs better.
20250126
Judging from the error message, this problem may not have much to do with the compiler. It looks like MATLAB recognizes the variable cmdFilesList as a function during the execution of internal code. You may want to check your workspace and search path for issues with this variable or any other name that might be the same as a function built into MATLAB.
3 Comments
More Answers (0)
See Also
Categories
Find more on Call C++ from MATLAB 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!