Apple Mach-O 链接器 (ld) 使用 Switch 语句时出错?
我正在创建一个 Objective-C 程序,当调用 C 函数时,它将尝试转换数字并返回字符串。然而,当我尝试编译时,这导致了 Apple Mach-O Linker (ld) 错误。
这是代码片段:
NSString * convertNum (int theNum) {
NSString *numString;
switch (theNum) {
case 102:
numString = @"Oh yea, string 102";
break;
case 104:
numString = @"Oh great, string 104";
break;
/* ... */
default:
numString = @"Don't feed me with something I don't know!";
break;
}
return numString;
}
我做错了什么吗?我正在使用 Xcode 4。非常感谢。
I am creating an Objective-C program that when calling a C function, it will try to convert a number and return a string. However this caused an Apple Mach-O Linker (ld) Error when I tried to compile.
Here's the code snippet:
NSString * convertNum (int theNum) {
NSString *numString;
switch (theNum) {
case 102:
numString = @"Oh yea, string 102";
break;
case 104:
numString = @"Oh great, string 104";
break;
/* ... */
default:
numString = @"Don't feed me with something I don't know!";
break;
}
return numString;
}
Did I do anything wrong? I am using Xcode 4. Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
链接错误通常意味着方法、函数或类似的东西有原型声明,但没有在任何地方实现。这也可能意味着您尚未在应用程序中包含库或框架,但您正在使用该库或框架中的头文件。
另外,您对 numString 的使用也很好,您将返回指向静态字符串的指针,它们是在编译时生成的。
Linking error usually means something like a method, function or something similar has the prototype declare but it is not implemented anywhere. It can also mean you have not included a library or framework in you application but you are using the header files from that library or framework.
Also your use of numString is fine, you are returning pointers to strings that are static, they generated at compile time.