"collect2.exe: error: Id returned 1 exit status" when building S-function

18 次查看(过去 30 天)
I am trying to build an S-function for use in a Simulink model on my Windows machine. But when I try to build it, I get an error that looks like this:
C:\Users\xxx\AppData\Local\Temp\mex_6822034771356968_15704\SourceCode.obj:SourceCode.c:(.text+0x316): undefined reference to `__imp_closesocket'
C:\Users\xxx\AppData\Local\Temp\mex_6822034771356968_15704\SourceCode.obj:SourceCode.c:(.text+0x323): undefined reference to `__imp_WSACleanup'
C:\Users\xxx\AppData\Local\Temp\mex_6822034771356968_15704\SourceCode.obj:SourceCode.c:(.text+0x401): undefined reference to `__imp_recv'
C:\Users\xxx\AppData\Local\Temp\mex_6822034771356968_15704\SourceCode.obj:SourceCode.c:(.text+0x5a3): undefined reference to `__imp_WSAStartup'
C:\Users\xxx\AppData\Local\Temp\mex_6822034771356968_15704\SourceCode.obj:SourceCode.c:(.text+0x5c1): undefined reference to `__imp_gethostbyname'
C:\Users\xxx\AppData\Local\Temp\mex_6822034771356968_15704\SourceCode.obj:SourceCode.c:(.text+0x5e7): undefined reference to `__imp_htons'
C:\Users\xxx\AppData\Local\Temp\mex_6822034771356968_15704\SourceCode.obj:SourceCode.c:(.text+0x615): undefined reference to `__imp_socket'
C:\Users\xxx\AppData\Local\Temp\mex_6822034771356968_15704\SourceCode.obj:SourceCode.c:(.text+0x61c): undefined reference to `__imp_connect'
C:\Users\xxx\AppData\Local\Temp\mex_6822034771356968_15704\SourceCode.obj:SourceCode.c:(.text+0x742): undefined reference to `__imp_WSAGetLastError'
C:\Users\xxx\AppData\Local\Temp\mex_6822034771356968_15704\SourceCode.obj:SourceCode.c:(.text+0xfdd): undefined reference to `__imp_recv'
C:\Users\xxx\AppData\Local\Temp\mex_6822034771356968_15704\SourceCode.obj:SourceCode.c:(.text+0x3987): undefined reference to `__imp_closesocket'
C:\Users\xxx\AppData\Local\Temp\mex_6822034771356968_15704\SourceCode.obj:SourceCode.c:(.text+0x398d): undefined reference to `__imp_WSACleanup'
collect2.exe: error: ld returned 1 exit status
It does not seem to matter whether I use the command line or the S-function builder. My colleagues seem able to build the function, so it does not appear to be a bug.

采纳的回答

MathWorks Support Team
Usually, this indicates that the winsock library is missing.
Troubleshooting steps:
1. Are you able to build a simple MEX example such as "arrayProduct.c"?
2. Confirm that only the ws_2_32.lib is on the path and mex is configured to use the MinGW64 compiler. Then, try running:
>> mex -lws2_32 SourceCode.c
3. Try reinstalling Windows SDK.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Block and Blockset Authoring 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by