-
Notifications
You must be signed in to change notification settings - Fork 187
'Sleep' not working when compiled in Win32 (x86) #738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thank you for reporting the bug. |
@jvdp1 Good question. It might be an ifort specificity on Windows. I do not have access to other compilers at the moment. I may be able to give it a try with gfortran and keep you posted. As far as I know the pragma _WIN32/_WIN64 are only standard for ifort (maybe ifx) on Windows, so the proposed code would only work with ifort anyway. |
After playing around with different function names I figured out that one should call #ifdef _WIN32
subroutine winsleep(dwMilliseconds) bind (C, name='_sleep')
import :: DWORD
integer(DWORD) :: dwMilliseconds
end subroutine
#else
integer(c_int) function usleep(usec) bind (C)
import c_int
integer(c_int), value, intent(in) :: usec
end function
#endif (and I specified use, intrinsic :: iso_c_binding, only : DWORD => c_long) |
I finally found an answer to whether or not the @4 is Intel specific or not (I am quoting S. Lionel here):
But it looks like bad practice anyway 🤔 |
Thank you @davidpfister for this explanation. However, it is still not clear to me what we should do to solve this issue. What would you suggest as the best way to solve this issue? |
Hi @jvdp1,
subroutine winsleep(dwMilliseconds) bind(C, name='Sleep')
!DEC$ ATTRIBUTES STDCALL :: Sleep
!GCC$ ATTRIBUTES STDCALL :: Sleep
import :: DWORD
integer(DWORD), value :: dwMilliseconds
end subroutine IMHO, the last option should be the way to go. |
Thank you @davidpfister for the summary.
If I am right, these two directives are only for intel and GCC compilers. So, I am a bit afraid that this solution will not work with other compilers. Is it right? |
It's true that it is not standard compliant. |
I would absolutely refrain from using $DEC statements, and advocate to go for a C wrapper. |
If I understand correctly |
Yep, #ifdef _WIN32
#ifdef _WIN64
subroutine winsleep(dwMilliseconds) bind (C, name='Sleep')
import :: DWORD
integer(DWORD) :: dwMilliseconds
end subroutine
#else
subroutine winsleep(dwMilliseconds) bind (C, name='_sleep')
import :: DWORD
integer(DWORD) :: dwMilliseconds
end subroutine
#endif
#else It has been tested on W10 with ifort 2020 and it works as expected in Win32 and x64. |
Description
The Sleep function does not even compile on Windows using ifort (ia-32 2021.5.0). One gets
fatal error LNK1120: 1 unresolved external
error LNK2019: unresolved external symbol _Sleep
It works fine when building in x64 though.
Expected Behaviour
The code should compile for x86 and x64 platforms.
Version of stdlib
v0.3.0
Platform and Architecture
Windows
Additional Information
After playing around I came up with a solution that works for me.
In x86 the sleep function on Windows should be called
Sleep@4
.I changed the code as follows
and the whole thing works like a charm
The text was updated successfully, but these errors were encountered: