Error using build after clibgen.generateLibraryDefinition runs as expected.
36 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
埃博拉酱
2025 年 1 月 25 日 11:30
編集済み: 埃博拉酱
2025 年 1 月 26 日 9:49
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Call C++ from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!