MinGW64 compiler fails to create the mex file

10 views (last 30 days)
I'm trying to convert the pnet.c file into a mex-file. I have windows 10 and Matlab 2021a. When I use the code
mex -O pnet.c 'C:\Program Files\MATLAB\R2021a\sys\lcc64\lcc64\lib64\wsock32.lib' -DWIN64
I get the following errors. Any suggestions how I can fix this issue?
:\Users\padid\AppData\Local\Temp\mex_84711572291662_11824\pnet.obj:pnet.c:(.text+0x8ba): undefined
reference to `__imp_timeGetTime'
C:\Users\padid\AppData\Local\Temp\mex_84711572291662_11824\pnet.obj:pnet.c:(.text+0x15c3): undefined
reference to `__imp_timeGetTime'
C:\Users\padid\AppData\Local\Temp\mex_84711572291662_11824\pnet.obj:pnet.c:(.text+0x1a36): undefined
reference to `__imp_timeGetTime'
C:\Users\padid\AppData\Local\Temp\mex_84711572291662_11824\pnet.obj:pnet.c:(.text+0x2013): undefined
reference to `__imp_timeGetTime'
collect2.exe: error: ld returned 1 exit status

Answers (1)

Pratyush
Pratyush on 18 Apr 2024
Hi Padideh,
To resolve the linker errors you're encountering when trying to convert pnet.c into a mex-file in MATLAB 2021a on Windows 10, you need to link against the winmm.lib library in addition to wsock32.lib. This is because the errors are due to undefined references to the timeGetTime function, which is defined in winmm.lib, not wsock32.lib. You can do this by modifying your mex command to include -lwinmm or by specifying the full path to winmm.lib if necessary. If you don't know the path or the library is not found, you may need to locate winmm.lib on your system or install the Windows SDK to get it.

Community Treasure Hunt

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

Start Hunting!