简体   繁体   English

在XCode上使用I / O Kit中的方法时,构建失败

[英]Build fails when using methods from I/O Kit on XCode

I need to perform some operations in my C++ app upon sleep and wake up of Mac OS. 睡眠和唤醒Mac OS时,我需要在C ++应用程序中执行一些操作。 I am being pointed to using I/O Kit. 我指的是使用I / O套件。

I followed this guide , specifically "Listing 3". 我遵循了本指南 ,特别是“清单3”。 No build errors occurred with the #include directives for IOKit . IOKit#include指令未发生构建错误。

However, build fails when I uncomment IOAllowPowerChange() or IOCancelPowerChange() : 但是,当我取消注释IOAllowPowerChange()IOCancelPowerChange()时,构建失败:

Undefined symbols for architecture x86_64:
  "_IOAllowPowerChange", referenced from:
      SleepCallback(void*, unsigned int, unsigned int, void*) in MyAppFrameWork.a(PowerWatcher.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I tried adding IOKit.framework in Project Settings > Build Phases > Link Binary With Libraries, which didn't change anything. 我尝试在“项目设置”>“构建阶段”>“使用库链接二进制文件”中添加IOKit.framework ,但未做任何更改。

What am I missing? 我想念什么?

EDIT 编辑

Same error occurs when using any method from I/O Kit, including: IONotificationPortGetRunLoopSource() and IORegisterForSystemPower() . 使用I / O Kit中的任何方法时,都会发生相同的错误,包括: IONotificationPortGetRunLoopSource()IORegisterForSystemPower()

No errors though when declaring variables, for example for IONotificationPortRef 声明变量时没有错误,例如IONotificationPortRef

It really should be solved by linking against IOKit.framework. 确实应该通过链接IOKit.framework来解决。 Are you sure you added it to the right target? 您确定将其添加到正确的目标吗? You need to link against it in the final executable or framework. 您需要在最终的可执行文件或框架中链接它。 Static libraries can't link against frameworks. 静态库无法链接到框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM