如何让 TextMate 处理导入的文件?
我正在使用 TextMate 做一些 Objective-C 练习。当所有内容都在一个文件中时,它工作正常,但一旦我想处理多个文件,它就会出错。例如,我有一个单独的 Rectangle.h 文件要导入:
#import "Rectangle.h"
int main (int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Rectangle *rectangle = [[Rectangle alloc] init];
[pool drain];
return 0;
}
运行时出现此错误:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_Rectangle", referenced from:
objc-class-ref in ccccStDD.o
ld: symbol(s) not found for architecture x86_64
我正在使用 C 包的“运行”命令。使用 Xcode 包的“Build & Run”命令给了我一个不同的错误。
如何让 TextMate 导入我的 Rectangle.h 文件并运行?
I'm using TextMate to do some Objective-C exercises. When everything is in one file, it works fine, but as soon as I want to work with multiple files it gives an error. For example, I have a separate Rectangle.h
file to be imported:
#import "Rectangle.h"
int main (int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Rectangle *rectangle = [[Rectangle alloc] init];
[pool drain];
return 0;
}
Running gives this error:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_Rectangle", referenced from:
objc-class-ref in ccccStDD.o
ld: symbol(s) not found for architecture x86_64
I'm using the C bundle's "Run" command. Using the Xcode bundle's "Build & Run" command gives me a different error.
How can I make TextMate import my Rectangle.h
file and run?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是编译器错误,而是链接器错误。
您的导入应该没问题,只要它与主文件位于同一目录中即可。
我想您还应该有一个 Rectangle.m 文件。您需要将两个文件(
Rectangle.m
和主文件)编译为目标文件(使用-c
参数),然后将它们链接在一起以生成可执行文件。或者简单地将两个文件一起编译:
请注意,如果您的头文件位于单独的目录中,则可以使用
-i
或-I
参数将其指定给 GCC。编辑:
我刚刚看到有人提到 Xcode。您使用的是 Xcode 还是 TextMate?
如果您使用 Xcode 进行编译并收到错误,则您的 Rectangle.m 文件可能不是主 Xcode 目标的一部分。
It's not a compiler error, but a linker error.
Your import should be fine, as long as it's in the same directory as your main file.
I guess you should also have a
Rectangle.m
file. You need to compile both files (Rectangle.m
and your main file) as object files (with the-c
argument), and then link them together to produce an executable.Or simply compile both files together:
Note that if your header files are in a separate directory, you can specify it to GCC using the
-i
or-I
arguments.EDIT:
I've just seen a mention of Xcode. Are you using Xcode or TextMate?
If you compile using Xcode, and get the error, it's likely that your
Rectangle.m
file is not part of your main Xcode target.