7

我正在尝试使用 I/O 套件并已正确链接到 I/O 套件。

当我在 I/O 套件中使用函数并且不在静态函数中调用它时,我收到以下错误Undefined symbols for architecture x86_64

这是一个抑制错误的示例

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

    }
}

这是一个将导致错误的示例。

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

    }
}

关于为什么会发生这种情况的任何建议?

编辑:

以下是确切的错误消息:

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)
4

1 回答 1

2

好的,我有一个可能发生这种情况的情况。如果从不调用静态函数,则不会出现链接时间错误。

比如我用这个函数写了一个简单的c文件,并undef_foobar没有定义:

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

现在,如果foobar()从 my 调用main(),我会收到错误消息:

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

如果在这个 c 文件中根本没有调用该函数,则没有链接器错误。

于 2011-10-07T07:33:56.277 回答