Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting error LNK2019 when building S-function in Simulink

263 views
Skip to first unread message

Tope

unread,
May 31, 2011, 11:19:04 AM5/31/11
to
I have cpp code which I use to control phidget motors. My code is in a file called motor.cpp which requires the phidget21.h and phidget21.lib. I am able to get the mex function by running
mex motor.cpp phidget21.h. But when I try to build the model containing the S-function I get an LNK2019 error for each function that my motor.cpp files tries to use. This is the error message:

### Linking ...
C:\PROGRA~1\MATLAB\R2009a\sys\perl\win32\bin\perl C:\PROGRA~1\MATLAB\R2009a\rtw\c\tools\mkvc_lnk.pl phidget2.lk phidget2.obj phidget2_data.obj phidget2_main.obj rtGetInf.obj rtGetNaN.obj rt_matrx.obj rt_nonfinite.obj rt_printf.obj rt_sim.obj phidget_motor_control3.obj
link /RELEASE /INCREMENTAL:NO /NOLOGO -subsystem:console,5.0 /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:msvcrtd.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcprtd.lib extmode_quarc_r2009a.lib quanser_communications.lib kernel32.lib ws2_32.lib mswsock.lib advapi32.lib msvcprt.lib winmm.lib /MANIFESTFILE:phidget2.manifest @phidget2.lk @phidget2_ref.rsp quanser_runtime.lib quanser_common.lib shell32.lib -out:..\phidget2.rt-windows
phidget_motor_control3.obj : error LNK2019: unresolved external symbol __imp__CPhidgetAdvancedServo_setEngaged@12 referenced in function "void __cdecl mdlInitializeSizes(struct SimStruct_tag *)" (?mdlInitializeSizes@@YAXPAUSimStruct_tag@@@Z)
phidget_motor_control3.obj : error LNK2019: unresolved external symbol __imp__CPhidgetAdvancedServo_setServoType@12 referenced in function "void __cdecl mdlInitializeSizes(struct SimStruct_tag *)" (?mdlInitializeSizes@@YAXPAUSimStruct_tag@@@Z)
phidget_motor_control3.obj : error LNK2019: unresolved external symbol __imp__CPhidget_getErrorDescription@8 referenced in function "void __cdecl mdlInitializeSizes(struct SimStruct_tag *)" (?mdlInitializeSizes@@YAXPAUSimStruct_tag@@@Z)
phidget_motor_control3.obj : error LNK2019: unresolved external symbol __imp__CPhidget_waitForAttachment@8 referenced in function "void __cdecl mdlInitializeSizes(struct SimStruct_tag *)" (?mdlInitializeSizes@@YAXPAUSimStruct_tag@@@Z)
phidget_motor_control3.obj : error LNK2019: unresolved external symbol __imp__CPhidget_open@8 referenced in function "void __cdecl mdlInitializeSizes(struct SimStruct_tag *)" (?mdlInitializeSizes@@YAXPAUSimStruct_tag@@@Z)
phidget_motor_control3.obj : error LNK2019: unresolved external symbol __imp__CPhidgetAdvancedServo_create@4 referenced in function "void __cdecl mdlInitializeSizes(struct SimStruct_tag *)" (?mdlInitializeSizes@@YAXPAUSimStruct_tag@@@Z)
phidget_motor_control3.obj : error LNK2019: unresolved external symbol __imp__CPhidgetAdvancedServo_getPosition@12 referenced in function "void __cdecl mdlOutputs(struct SimStruct_tag *,int)" (?mdlOutputs@@YAXPAUSimStruct_tag@@H@Z)
phidget_motor_control3.obj : error LNK2019: unresolved external symbol __imp__CPhidgetAdvancedServo_setPosition@16 referenced in function "void __cdecl mdlOutputs(struct SimStruct_tag *,int)" (?mdlOutputs@@YAXPAUSimStruct_tag@@H@Z)
phidget_motor_control3.obj : error LNK2019: unresolved external symbol __imp__CPhidget_delete@4 referenced in function "void __cdecl mdlTerminate(struct SimStruct_tag *)" (?mdlTerminate@@YAXPAUSimStruct_tag@@@Z)
phidget_motor_control3.obj : error LNK2019: unresolved external symbol __imp__CPhidget_close@4 referenced in function "void __cdecl mdlTerminate(struct SimStruct_tag *)" (?mdlTerminate@@YAXPAUSimStruct_tag@@@Z)
..\phidget2.rt-windows : fatal error LNK1120: 10 unresolved externals
NMAKE : fatal error U1077: '"c:\program files\microsoft visual studio 9.0\VC\BIN\link.EXE"' : return code '0x460'
Stop.

I am using the Visual Studio 2008 compiler. The error message looks like my cpp file is unable to access the header and lib files but I have everything in the same folder. Can someone tell me why I would get these errors?
Thanks

Praetorian

unread,
May 31, 2011, 2:06:26 PM5/31/11
to Tope
You need to tell the mex command to link against the library file. Your mex command should look like:

mex motor.cpp -l phidget21.lib

There is no need to list the header file in the command, the header should be included by motor.cpp. Another, MSVC-specific way to do this, is to add #pragma comment(lib, "phidget21") within motor.cpp, this allows you exclude listing the library file in the mex command.

Regards,
Ashish.

0 new messages