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

倾然丶 夕夏残阳落幕 提交于 2019-12-11 22:11:47

问题


I need to perform some operations in my C++ app upon sleep and wake up of Mac OS. I am being pointed to using I/O Kit.

I followed this guide, specifically "Listing 3". No build errors occurred with the #include directives for IOKit.

However, build fails when I uncomment IOAllowPowerChange() or 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.

What am I missing?

EDIT

Same error occurs when using any method from I/O Kit, including: IONotificationPortGetRunLoopSource() and IORegisterForSystemPower().

No errors though when declaring variables, for example for IONotificationPortRef


回答1:


It really should be solved by linking against 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.



来源:https://stackoverflow.com/questions/38119627/build-fails-when-using-methods-from-i-o-kit-on-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!