Error using build after clibgen.ge​nerateLibr​aryDefinit​ion runs as expected.

36 ビュー (過去 30 日間)
Andrew
Andrew 2025 年 1 月 24 日 21:31
コメント済み: 埃博拉酱 2025 年 1 月 27 日 1:03
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.

採用された回答

埃博拉酱
埃博拉酱 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 件のコメント
Andrew
Andrew 2025 年 1 月 26 日 17:49
Still not really sure what the underlying issue was, but I tried it on a different device with the MinGW-w64 compiler instead, and everything seemed to run as expected there. I'll add a comment if I ever work out the source of the issue, but for now I think I can proceed without fully understanding it.
埃博拉酱
埃博拉酱 2025 年 1 月 27 日 1:03
@Andrew The key is that you switch to a different device and solve the potential duplicate name problem. I still don't think the compiler is the key.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall C++ from MATLAB についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by