【问题标题】:Build fails when using methods from I/O Kit on XCode在 XCode 上使用 I/O Kit 中的方法时构建失败
【发布时间】:2016-11-02 08:15:06
【问题描述】:

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

我关注了this guide,特别是“清单 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)

我尝试在 Project Settings > Build Phases > Link Binary With Libraries 中添加 IOKit.framework,但这并没有改变任何内容。

我错过了什么?

编辑

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

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

【问题讨论】:

    标签: c++ xcode macos build iokit


    【解决方案1】:

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

    【讨论】:

    • 你是对的,我把它添加到了错误的目标,一个框架。
    猜你喜欢
    • 2018-04-08
    • 1970-01-01
    • 2022-11-14
    • 2019-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多