Objective-C 和 MATLAB/Octave 文件扩展名之间的重叠

发布于 2024-11-28 08:19:33 字数 135 浏览 0 评论 0原文

除了 .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技术交流群

发布评论

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

评论(3

眉黛浅 2024-12-05 08:19:33

我看到的唯一方法是为每个程序创建子目录并将文件放在那里。您可以告诉 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.

一个人的夜不怕黑 2024-12-05 08:19:33

解决方法是对 Objective-C 使用 .mm.mm 用于 Objective-C++ 源文件,它是 Objective-C 的超集,因此应该可以正常编译。

这绝不是一个干净的解决方案。更好的方法是按照 Ruddy Velthuis 的建议将文件夹重新组织为子文件夹,或者简单地调用源文件 hello-objective-cmhello-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 and hello-matlab.m.

秋心╮凉 2024-12-05 08:19:33

MATLAB 无法找到文件,除非它们具有 .m 扩展名(非常重要!)

现在我对 Objective-C 知之甚少,我认为它是 C 的超集(就像 C++ 一样)。如果是这样,与 C/C++ 类似,您应该能够将任何文件名作为输入传递给编译器:

g++ -c myfile.m.txt

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:

g++ -c myfile.m.txt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文