سؤال

I am attempting to use I/O kit and have linked to I/O kit properly.

When I use a function in I/O kit and don't call it within a static function, I get the following error Undefined symbols for architecture x86_64.

Here is an example to suppress the error

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

    }
}

Here is an example that will cause the 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)
هل كانت مفيدة؟

المحلول

Okay I got one scenario when this can happen. If the static function is never called, you won't get that link time error.

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

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

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

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

If the function isn't called at all from within this c file, there are no linker errors.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top