clib Build error: 'The command line is too long.'

5 views (last 30 days)
When I use the following commands to build my C++ Interface in MATLAB
clibgen.generateLibraryDefinition( hppFiles, ..."SupportingSourceFiles", sources, ..."IncludePath", includePath);defineDllWrapper;build(defineDllWrapper)
I get the following error.
"Building interface file 'DllWrapperInterface.dll'.Error using clibgen.internal.buildHelper (line 62)Build failed with error:'The command line is too long."
Why am I getting this error and how can I fix it?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Oct 2021
Edited: MathWorks Support Team on 7 Oct 2021
The Windows OS has a command-line limit of 32,767 characters. When building large projects, this limit may exceeded, especially during the linking step. Currently, this limitation applies to the clib build processes. However there are some workarounds that may help to avoid this issue:
1) Specify a short "OutputFolder" name. The example below shows how to specify the "OutputFolder" as "C:\".
clibgen.generateLibraryDefinition( hppFiles, "SupportingSourceFiles", sources, …"IncludePath", includePath, …"OutputFolder","C:\")
You can find the documentation for the "OutputFolder" name/value pair at the link below.
https://www.mathworks.com/help/releases/R2021a/matlab/ref/clibgen.generatelibrarydefinition.html#mw_f7ebe4fe-eb45-41b6-813d-7f59ff61adae
2) Use the Windows subst command to shorten path names. For example,
> subst b: c:\<very-long-path-name>
3) Break the code into smaller DLLs. For example, create a DLL outside MATLAB for portions of the code that do not require a MATLAB interface. These DLLs can be linked during the build. The example below illustrates a case where the static library foo.lib was created from a subset of the code and is linked to when building the MATLAB clib Interface.
clibgen.generateLibraryDefinition( hppFilesReduced,"Libraries", "foo.lib", ...
"SupportingSourceFiles", sourcesReduced, …"IncludePath", includePath, …"OutputFolder","C:\")

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!