- Change your MATLAB compiler setting to match the one used for your library (if you have that compiler installed)
- Or rebuild your library using the compiler that MATLAB is currently set to use
Unsolved external symbol in C++ interface build
6 views (last 30 days)
Show older comments
I have a C++ function which I can load on MATLAB with
loadlibrary('nc_driver_x64')
and this works without problem using calllib.
On the other hand, if I try to create interface of the same function like this
clibgen.generateLibraryDefinition(fullfile(workPath,'nc_driver_x64.h'),...
"IncludePath", workPath,...
"Libraries", {fullfile(workPath,'nc_driver_x64.lib'), fullfile(workPath,'nc_driver_x64.dll')},...
"Verbose",true)
It generates definenc_driver_x64.m and definenc_driver_x64.mlx, but then
build(definenc_driver_x64)
returns nc_driver_x64Interface.obj : error LNK2019: on all functions in this file.
.h, .lib and .dll files are all in the same folder and running on R2021b
I really appreciate if you could point out what I should check to make this work!
0 Comments
Answers (1)
Madheswaran
on 20 Feb 2025
I think the problem you are facing is because of a compiler mismatch between the one used to build your C++ library and the one MATLAB is using to build the interface. Since your library works fine with "loadlibrary" and "calllib", but fails during the "build(definenc_driver_x64)" step with LNK2019 errors (unresolved external symbols), this suggests the interface building process is using a different compiler than what was used to create your original library.
To solve this, you should check which compiler was used to build your original "nc_driver_x64" library and make sure MATLAB is using the same compiler when building the interface.
The list of suitable and compatible compilers is listed here: https://www.mathworks.com/support/requirements/supported-compilers.html
You can check your current MATLAB C++ compiler setting with:
mex -setup cpp
This will show you which compiler MATLAB is currently using. You can find more information here: https://www.mathworks.com/help/matlab/ref/generatecinterface.html
If the compiler MATLAB currenlty using doesn't match the compiler used for your library, you'll need to either:
You can also find possible trouble shooting steps to resolve build errors here: https://www.mathworks.com/help/matlab/matlab_external/resolve-build-error-unresolved-external-symbols.html
Hope this helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!