"collect2.exe: error: Id returned 1 exit status" when building S-function
14 views (last 30 days)
Show older comments
MathWorks Support Team
on 26 Jan 2022
Answered: MathWorks Support Team
on 17 Feb 2022
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.
Accepted Answer
MathWorks Support Team
on 26 Jan 2022
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 Comments
More Answers (0)
See Also
Categories
Find more on Block and Blockset Authoring in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!