Including a DLL which was generated with MATLAB Coder

Hello,
I generated a very basic DLL following the instructions (https://de.mathworks.com/help/coder/gs/generating-c-code-from-matlab-code-using-the-matlab-coder-project-interface.html) only changing for DLL instead of LIB. The file "distance.m" looks like this:
function res = distance(a, b)
res = b-a;
end
Then I tried to include it in my Visual Studio 2022 Project which just consist of
#include <iostream>
#include "distance.h"
int main()
{
distance(1, 2);
}
I followed the instructions here (https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=msvc-170) to include the directory.
When I build the project, it gives me the Linker Tools Error LNK2001: unresolved external symbol "__IMPORT_DESCRIPTOR_distance" (and following LNK1120).
I already tried it with a basic DLL generated in VS with no problems at all. I only fail with DLLs generated with MATLAB Coder.
Can someone help me with this?
Thanks in advance!
Philipp

댓글 수: 3

Infinite_king
Infinite_king 2024년 1월 12일
편집: Infinite_king 2024년 1월 12일
Make sure that you are using the same compiler to generate the DLL. Could you confirm which compiler you used when generating the DLL with MATLAB Coder?
I think that is the problem. I'll try it with the VS compiler as soon I got VS installed and let you know the results.
Sorry for the late answer, I had some license issues with VS.
Using the VS compiler for the DLL fixed the problem.

댓글을 달려면 로그인하십시오.

답변 (1개)

Mukund Sankaran
Mukund Sankaran 2024년 1월 12일
편집: Mukund Sankaran 2024년 1월 12일

0 개 추천

Hello Philipp,
There's an example in our documentation that walks through the steps for integrating a DLL generated by MATLAB Coder with a Microsoft Visual Studio project. Have you given that a try ?

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품

릴리스

R2023b

질문:

2024년 1월 12일

댓글:

2024년 1월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by