2016-05-10 10 views
0

Linuxでmingwを使用していますが、Windows用にコンパイルしようとしています。私はCMakeを使用しており、ouptutは.exeファイルでなければなりません。 私のプログラムでは、user32.dll/user32.libにあるWinAPI呼び出し(RegisterPowerSettingNotification)を使用しています。私の.exeをuser32.dllのバージョンから独立させたい(私の.exeはWindows8/8.1/10上で動作するはずです)。Linux(クロス)でコンパイルするとcmakeのuser32.dllに "リンク"します

マイCmakeLists.txt:

Linking C executable myexeservice.exe 
CMakeFiles/myexeservice.dir/objects.a(win_service.c.obj):win_service.c:(.text+0x393): undefined reference to `RegisterPowerSettingNotification' 
collect2: error: ld returned 1 exit status 

私が知っている:リンク時と

/.../win_service.c:182:27: warning: assignment makes pointer from integer without a cast [enabled by default] 
lidcloseRegHandle = RegisterPowerSettingNotification(serviceStatusHandle, &GUID_LIDCLOSE_ACTION,... 

:私はコンパイルしていたとき、私は警告を受けています

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR} 
    ${USBHID_HEADER} 
    ) 
#USER32 // Will find the user32.lib 
find_library(USER32 user32) 
list(APPEND USBHID_LIB_DEPS ${USER32}) 
find_path(USBHID_HEADER winuser.h) 
list(APPEND INCLUDES ${USBHID_HEADER}) 

# add the executable 
add_executable(myexe win_service.c resource.rc) 
target_link_libraries(myexe LINK_PUBLIC ${USBHID_LIB_DEPS}) 
set_target_properties(myexe PROPERTIES OUTPUT_NAME "MyExeService") 
install(TARGETS myexe DESTINATION bin) 

DLLとのリンクは意味がありませんが、私はRegisterPowerSettingNotificationを見ないようにCMakeをだますことができますか?

答えて

0

RegisterPowerSettingNotificationは、Windows Vistaをご利用のお客様にご利用いただけます。 LinuxでMinGWでコンパイルすると、デフォルトでWINVERは0x502(Windows Server 2003)です:/usr/share/mingw-w64/include/_mingw.h、RegisterPowerSettingNotificationは定義されていません。

ソリューションは、あらゆる

#include <windows.h> 

WINVERおよび_WIN32_WINNTの定義の前に、追加することです。

#ifndef WINVER 
#define WINVER 0x0600 
#endif 

#ifndef _WIN32_WINNT 
#define _WIN32_WINNT 0x0600 
#endif 
関連する問題