Objective-C 和 MATLAB/Octave 文件扩展名之间的重叠
除了 .m
之外,Objective-C 或 MATLAB/Octave 是否还有源文件扩展名?我问这个问题是因为我将 Hello World 程序放在一个文件夹中,并且不能有两个 hello.m
文件。
Do Objective-C or MATLAB/Octave have source file extensions besides .m
? I ask because I'm putting Hello World programs in a single folder and I can't have two hello.m
files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我看到的唯一方法是为每个程序创建子目录并将文件放在那里。您可以告诉 Obj-C 将其他扩展视为 Obj-C,但这并不能解决其他程序的问题。
更新
要将任何扩展编译为 Objective-C,请在命令行上使用
-x Objective-c
或从目标构建设置中的“将源代码编译为”中选择 Objective-C。默认是“根据文件类型”,这意味着只有 .m 文件被编译为 Objective-C。FWIW,Objective-C++ 和 Objective-C 之间有许多细微的差别。正如我上面已经说过的,我自己会使用子文件夹来分隔 .m 文件。
The only way I see is to create subdirectories for each of the programs and put your files there. You can tell Obj-C to treat other extensions as Obj-C, but that would not solve the problem for the other programs.
Update
To compile any extension as Objective-C, use
-x objective-c
on the command line or Select Objective-C from "Compile Sources As" in the target build settings. Default is "According To File Type", which means that only .m files are compield as Objective-C.FWIW, there are many subtle differences between Objective-C++ and Objective-C. I myself would use subfolders to separate the .m files, as I already said above.
解决方法是对 Objective-C 使用
.mm
。.mm
用于 Objective-C++ 源文件,它是 Objective-C 的超集,因此应该可以正常编译。这绝不是一个干净的解决方案。更好的方法是按照 Ruddy Velthuis 的建议将文件夹重新组织为子文件夹,或者简单地调用源文件
hello-objective-cm
和hello-matlab.m
。A workaround would be to use
.mm
for Objective-C..mm
is used for Objective-C++ source files and it is a superset of Objective-C so it should compile fine.This is by no mean a clean solution. A much better way would be to reorganize your folder into subfolders as suggested by Ruddy Velthuis, or simply to call your source files
hello-objective-c.m
andhello-matlab.m
.MATLAB 无法找到文件,除非它们具有
.m
扩展名(非常重要!)现在我对 Objective-C 知之甚少,我认为它是 C 的超集(就像 C++ 一样)。如果是这样,与 C/C++ 类似,您应该能够将任何文件名作为输入传递给编译器:
MATLAB cannot find files unless they have the
.m
extension (very important!)Now I know very little about Objective-C, I presume it's a superset of C (just like C++ is). If so, and similar to C/C++, you should be able to pass any file name as input to the compiler: