Why do static functions exclude undefined characters in Xcode?

I am trying to use an I / O kit and am properly bound to an I / O kit.

When I use a function in an I / O set and do not call it in a static function, I get the following error Undefined symbols for architecture x86_64 .

Here is an example of error suppression

 static void test(void) { if (IORegisterForSystemPower(...)) { } } 

Here is an example that will result in an error.

 void test(void) { if (IORegisterForSystemPower(...)) { } } 

Any suggestions as to why this is happening?

EDIT:

Here are the exact error messages:

 Undefined symbols for architecture x86_64: "_IORegisterForSystemPower", referenced from: _registerNotificaitonUsingIOKit in AppDelegate.o "_IONotificationPortGetRunLoopSource", referenced from: _registerNotificaitonUsingIOKit in AppDelegate.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) 
+7
source share
1 answer

Well, I have one scenario when this can happen. If the static function is never called, you will not get this communication time error.

For example, I wrote a simple c file with this function, and undef_foobar not defined:

 static int foobar (void) { undef_foobar (); } 

Now, if foobar() is called from my main() , I get an error:

 Undefined symbols for architecture x86_64: "_undef_foobar", referenced from: 

If the function is not called at all from this c file, there are no linker errors.

+2
source

All Articles