Error LNK2019 (unresolved external symbol) when trying to integrate C function using Legacy Code Tool
이전 댓글 표시
I need to use C functions in a Simulink model using Legacy Code Tool. I'm trying to communicate with some hardware ( US Digital USB4 device), for which the vendor has provided a DLL (USB4.dll) & a C header file (USB4.h) including basic functions. I'm calling these basic functions in my own C function. This is the header file for my function ( "USB4init.h" )
int USB4init(short iDeviceCount);
This is the body of my function ( "USB4init.cpp" ):
#include "USB4.h"
#include "USB4init.h"
int USB4init(short iDeviceCount)
{
int iResult = 0;
iResult = USB4_Initialize(&iDeviceCount); // initialize the card
return iResult;
}
And I'm using these commands in Matlab prompt to make a MEX file from my C function:
def = legacy_code('initialize');
def.SourceFiles = {'USB4init.cpp'};
def.HeaderFiles = {'USB4init.h','USB4.h'};
def.SFunctionName = 'ex_sfun_USB4init';
def.OutputFcnSpec = 'int16 y1 = USB4init(int8 u1)';
legacy_code('sfcn_cmex_generate',def);
legacy_code('compile',def)
But I'm facing this error:
### Start Compiling ex_sfun_USB4init
mex('-IC:\Users\...\MATLAB', '-c', '-outdir', 'C:\Users\...\Temp\tp06a02ca7_d2d8_4315_8e39_cb0a5d511cbf', 'C:\Users\...\MATLAB\USB4init.cpp')
Building with 'Microsoft Visual C++ 2012'.
MEX completed successfully.
mex('ex_sfun_USB4init.c', '-IC:\Users\...\MATLAB', 'C:\Users\...\Temp\tp06a02ca7_d2d8_4315_8e39_cb0a5d511cbf\USB4init.obj')
Building with 'Microsoft Visual C++ 2012 (C)'.
Error using mex
Creating library ex_sfun_USB4init.lib and object ex_sfun_USB4init.exp
ex_sfun_USB4init.obj : error LNK2019: unresolved external symbol USB4init referenced in function mdlOutputs
USB4init.obj : error LNK2019: unresolved external symbol USB4_Initialize referenced in function "int __cdecl
USB4init(short)" (?USB4init@@YAHF@Z)
ex_sfun_USB4init.mexw64 : fatal error LNK1120: 2 unresolved externals
Error in legacycode.LCT/compile (line 368)
Error in legacycode.LCT.legacyCodeImpl (line 84)
Error in legacy_code (line 87)
[varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action, varargin{1:end});
All of the dll, header, and cpp files are inside the Matlab directory, and I'm using R2014a version. Any help is much appreciated!
댓글 수: 4
Walter Roberson
2015년 8월 12일
Are you using 32 bit MATLAB or 64? The dll is 32 bit and cannot be called from any 64 bit program.
Alireza Manzoori
2015년 8월 12일
Walter Roberson
2015년 8월 13일
It depends on which version you downloaded. There are two at http://www.usdigital.com/support/software/usb4-software one of which is 32 bit only.
Alireza Manzoori
2015년 8월 13일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!