Obay
Obay

Reputation: 3205

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. 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

Upvotes: 0

Views: 372

Answers (1)

pmdj
pmdj

Reputation: 23438

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.

Upvotes: 0

Related Questions