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

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

我需要在 Mac OS 睡眠和唤醒时在我的 C++ 应用程序中执行一些操作。我被指向使用 I/O 套件。

我关注 this guide,特别是 "Listing 3"。 IOKit.

#include 指令未发生构建错误

但是,当我取消注释 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)

我尝试在项目设置 > 构建阶段 > Link Binary With Libraries 中添加 IOKit.framework,但没有任何改变。

我错过了什么?

编辑

使用 I/O 工具包中的任何方法都会出现同样的错误,包括:IONotificationPortGetRunLoopSource()IORegisterForSystemPower()

声明变量时没有错误,例如 IONotificationPortRef

确实应该通过 link 反对 IOKit.framework 来解决。您确定将其添加到正确的目标吗?您需要 link 在最终的可执行文件或框架中反对它。静态库不能 link 针对框架。