惰性符号绑定失败:找不到符号:_arc4random_uniform

发布于 2024-12-17 22:23:28 字数 1520 浏览 2 评论 0原文

所以我编写了一个 iOS 游戏,并使用 arc4random_uniform 来选择随机加电。

在 Sim 上,它工作正常,但在我的手机上它会抛出此错误(来自系统日志):

Nov 26 13:44:26 iPhone ----[2184]: placePowerupCalled
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.-----[0x1f08][2184]: dyld:  lazy symbol binding failed: Symbol not found: _arc4random_uniform
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.-----[0x1f08][2184]:   Referenced from: /Applications/------.app/-----
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.------[0x1f08][2184]:         Expected in: /usr/lib/libSystem.B.dylib
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.------[0x1f08][2184]: dyld: Symbol not found: _arc4random_uniform
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.-----[0x1f08][2184]:   Referenced from: /Applications/------.app/-------
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.-----[0x1f08][2184]:   Expected in: /usr/lib/libSystem.B.dylib
Nov 26 13:44:27 iPhone ReportCrash[2185]: Formulating crash report for process -----[2184]
 Nov 26 13:44:27 iPhone com.apple.launchd[1] (UIKitApplication:com.yourcompany.-----[0x1f08][2184]): (UIKitApplication:com.yourcompany.-----[0x1f08]) Job appears to have crashed: Trace/BPT trap
Nov 26 13:44:27 iPhone SpringBoard[2161]: Application '-----' exited abnormally with signal 5: Trace/BPT trap

我不太确定问题是什么。我什至包含了 arc4random 应该来自的头文件(#include“stdlib.h”),但这并没有起作用。

有人有什么想法吗?谢谢!:)


编辑:我尝试将二进制文件与“libSystem.b.dylib”库链接,但这也不起作用,并且仍然因相同的错误而崩溃。

So I programming an iOS game and I'm using arc4random_uniform for choosing a random powerup.

On the Sim, it works fine, but on my phone it throws this error (from the syslog):

Nov 26 13:44:26 iPhone ----[2184]: placePowerupCalled
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.-----[0x1f08][2184]: dyld:  lazy symbol binding failed: Symbol not found: _arc4random_uniform
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.-----[0x1f08][2184]:   Referenced from: /Applications/------.app/-----
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.------[0x1f08][2184]:         Expected in: /usr/lib/libSystem.B.dylib
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.------[0x1f08][2184]: dyld: Symbol not found: _arc4random_uniform
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.-----[0x1f08][2184]:   Referenced from: /Applications/------.app/-------
Nov 26 13:44:26 iPhone UIKitApplication:com.yourcompany.-----[0x1f08][2184]:   Expected in: /usr/lib/libSystem.B.dylib
Nov 26 13:44:27 iPhone ReportCrash[2185]: Formulating crash report for process -----[2184]
 Nov 26 13:44:27 iPhone com.apple.launchd[1] (UIKitApplication:com.yourcompany.-----[0x1f08][2184]): (UIKitApplication:com.yourcompany.-----[0x1f08]) Job appears to have crashed: Trace/BPT trap
Nov 26 13:44:27 iPhone SpringBoard[2161]: Application '-----' exited abnormally with signal 5: Trace/BPT trap

I'm not quite sure what the problem is. I've even included the header file arc4random should come from (#include "stdlib.h"), but that hasn't worked.

Anyone have any ideas? Thanks !:)


EDIT: I tried linking binary with the "libSystem.b.dylib" library, but that didn't work either and it's still crashing from the same error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情场扛把子 2024-12-24 22:23:28

arc4_uniform 函数是在 iOS 4.3 中添加的,在较低版本上不会运行。看起来您在 4.3 或更高版本上运行模拟器,但您的设备具有较低的 iOS 版本。
如果您计划在低于 4.3 的版本上支持您的应用程序,请尝试使用它:

arc4random() % upperBoundExclusive

它可能不像 arc4_uniform 那样精确随机,但可以工作。

arc4_uniform function was added in iOS 4.3 and won't run on lower versions. Looks like you run simulator on 4.3 or higher but your device has lower iOS version.
If you plan to support your app on versions lower than 4.3, try using this instead:

arc4random() % upperBoundExclusive

It might be not as precisely random as arc4_uniform, but will work.

尾戒 2024-12-24 22:23:28

arc4random_uniform 在 iOS 4.3 以下不可用。幸运的是,iOS 将在运行时绑定此符号,如果它不可用,则将其分配为 null(因此会出现“惰性符号绑定”错误)。

因此,使用 arc4random_uniform 的最佳方法是首先检查它是否可用,如下所示:

#include <stdlib.h>
...
int r = 0;
if (arc4random_uniform != NULL)
    r = arc4random_uniform (100);
else
    r = (arc4random() % 100);

arc4random_uniform is not available below iOS 4.3. Luckily iOS will bind this symbol at runtime and assign it to null if it's not available (hence your "lazy symbol binding" errors).

So the best way to use arc4random_uniform is to check if it's available first, like this:

#include <stdlib.h>
...
int r = 0;
if (arc4random_uniform != NULL)
    r = arc4random_uniform (100);
else
    r = (arc4random() % 100);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文