gpt4 book ai didi

objective-c - Objective-C 中的外部;他们的行为与 C 不同吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:51:37 64 4
gpt4 key购买 nike

我需要在两个文件之间共享一个 const 值;所以我决定使用 const 变量,而不是保留一个神奇的数字。所以我在我的 appDelegate.m 中创建了一个 global 变量 const int viewTag = 100;然后以 extern const int viewTag; 访问它,但我收到以下链接器错误:

Undefined symbols for architecture i386:
"viewTag", referenced from:
-[xxxViewController launchxxx] in libxxx_iPad.a(xxxViewController.o)
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

但上述内容在普通 C、C++ 环境中是完全合法的。任何人都可以发出一些光吗?

更新:将 extern const int viewTag; 放入 header 并导入该 header 有效,但我真的不想为单个 const int 这样做p>

最佳答案

尝试放置:

extern const int viewTag;

appDelegate.h 中,然后在您需要访问 viewTag 的地方导入此 header 。

关于objective-c - Objective-C 中的外部;他们的行为与 C 不同吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8757289/

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