在Xcode上使用I/O套件的方法时,构建失败将失败

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

本文关键字:失败 方法 构建 套件 Xcode      更新时间:2023-10-16

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

我遵循了本指南,特别是"列表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)

我尝试在项目设置中添加 IOKit.framework>构建阶段>链接二进制与库,这没有更改任何内容。

我缺少什么?

编辑

使用I/O套件中的任何方法时会发生相同的错误,包括:IONotificationPortGetRunLoopSource()IORegisterForSystemPower()

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

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