public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* compilation fails with Win32 API call
@ 2011-09-20 15:35 Andrew Schulman
  2011-09-20 16:35 ` JonY
  2011-09-20 17:04 ` jojelino
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Schulman @ 2011-09-20 15:35 UTC (permalink / raw)
  To: cygwin

I'm trying to compile a program that calls the win32 function
SetThreadExecutionState, in kernel32.dll [1].  The link step fails:

$ gcc -c nosleep.c
$ gcc -o nosleep nosleep.o -lkernel32
nosleep.o:nosleep.c:(.text+0x1f): undefined reference to
`_SetThreadExecutionState'
nosleep.o:nosleep.c:(.text+0x5c): undefined reference to
`_SetThreadExecutionState'
collect2: ld returned 1 exit status

According to the FAQ [2], I shouldn't even have to include -lkernel32.

Can someone please tell me what I'm doing wrong?

Thanks,
Andrew.

[1] http://msdn.microsoft.com/en-us/library/aa373208(VS.85).aspx
[2]
http://www.cygwin.com/faq/faq.programming.html#faq.programming.win32-api


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: compilation fails with Win32 API call
  2011-09-20 15:35 compilation fails with Win32 API call Andrew Schulman
@ 2011-09-20 16:35 ` JonY
  2011-09-20 17:04 ` jojelino
  1 sibling, 0 replies; 4+ messages in thread
From: JonY @ 2011-09-20 16:35 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 981 bytes --]

On 9/20/2011 17:12, Andrew Schulman wrote:
> I'm trying to compile a program that calls the win32 function
> SetThreadExecutionState, in kernel32.dll [1].  The link step fails:
> 
> $ gcc -c nosleep.c
> $ gcc -o nosleep nosleep.o -lkernel32
> nosleep.o:nosleep.c:(.text+0x1f): undefined reference to
> `_SetThreadExecutionState'
> nosleep.o:nosleep.c:(.text+0x5c): undefined reference to
> `_SetThreadExecutionState'
> collect2: ld returned 1 exit status
> 
> According to the FAQ [2], I shouldn't even have to include -lkernel32.
> 
> Can someone please tell me what I'm doing wrong?
> 
> Thanks,
> Andrew.
> 
> [1] http://msdn.microsoft.com/en-us/library/aa373208(VS.85).aspx
> [2]
> http://www.cygwin.com/faq/faq.programming.html#faq.programming.win32-api
> 
> 

Hi,

There are a few possible causes.

1) You didn't include windows.h
2) You included it but didn't bump _WIN32_WINNT or equivalent.
3) The declaration is missing from winbase.h



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 196 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: compilation fails with Win32 API call
  2011-09-20 15:35 compilation fails with Win32 API call Andrew Schulman
  2011-09-20 16:35 ` JonY
@ 2011-09-20 17:04 ` jojelino
  2011-09-20 17:49   ` Andrew Schulman
  1 sibling, 1 reply; 4+ messages in thread
From: jojelino @ 2011-09-20 17:04 UTC (permalink / raw)
  To: cygwin

On 2011-09-20 PM 6:12, Andrew Schulman wrote:
> I'm trying to compile a program that calls the win32 function
> SetThreadExecutionState, in kernel32.dll [1].  The link step fails:
>
> $ gcc -c nosleep.c
> $ gcc -o nosleep nosleep.o -lkernel32
> nosleep.o:nosleep.c:(.text+0x1f): undefined reference to
> `_SetThreadExecutionState'
> nosleep.o:nosleep.c:(.text+0x5c): undefined reference to
> `_SetThreadExecutionState'
> collect2: ld returned 1 exit status
>
> According to the FAQ [2], I shouldn't even have to include -lkernel32.
>
> Can someone please tell me what I'm doing wrong?
>
> Thanks,
> Andrew.
>
> [1] http://msdn.microsoft.com/en-us/library/aa373208(VS.85).aspx
here you are.
http://msdn.microsoft.com/en-us/library/aa383745.aspx
> [2]
> http://www.cygwin.com/faq/faq.programming.html#faq.programming.win32-api
>
>
please define WINVER so that you can get definition what you want
(gcc -E -DWINVER=0x500 - <<EOF
#include <windows.h>
EOF
)|grep SetThreadExecution

now you can see SetThreadExecutionState is defined


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: compilation fails with Win32 API call
  2011-09-20 17:04 ` jojelino
@ 2011-09-20 17:49   ` Andrew Schulman
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Schulman @ 2011-09-20 17:49 UTC (permalink / raw)
  To: cygwin

> On 2011-09-20 PM 6:12, Andrew Schulman wrote:
> > I'm trying to compile a program that calls the win32 function
> > SetThreadExecutionState, in kernel32.dll [1].  The link step fails:
>
> please define WINVER so that you can get definition what you want
> (gcc -E -DWINVER=0x500 - <<EOF
> #include <windows.h>
> EOF
> )|grep SetThreadExecution

Thanks jojelino, and JonY too.  -DWINVER=0x500 did the trick.
Andrew.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-09-20 14:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-20 15:35 compilation fails with Win32 API call Andrew Schulman
2011-09-20 16:35 ` JonY
2011-09-20 17:04 ` jojelino
2011-09-20 17:49   ` Andrew Schulman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).