gpt4 book ai didi

objective-c - 为什么静态函数会消除 Xcode 中的 undefined symbol ?

转载 作者:太空狗 更新时间:2023-10-30 03:38:24 31 4
gpt4 key购买 nike

我正在尝试使用 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)

最佳答案

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

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

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

现在,如果从我的 main() 调用 foobar(),我会得到错误:

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

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

关于objective-c - 为什么静态函数会消除 Xcode 中的 undefined symbol ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7683579/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com