4

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.

mcandre
  • 22,868
  • 20
  • 88
  • 147

3 Answers3

3

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.

Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94
2

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.

Simon
  • 31,675
  • 9
  • 80
  • 92
  • 1
    There are many subtle differences between Objective-C and Objective-C++. I would use subfolders or compiler settings to use other extensions than .m for Objective-C. – Rudy Velthuis Aug 06 '11 at 04:56
0

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
mcandre
  • 22,868
  • 20
  • 88
  • 147
Amro
  • 123,847
  • 25
  • 243
  • 454
  • Even if the compiler can handle a single abnormal ObjC file extension, the various header files might not work well with them. – mcandre Aug 06 '11 at 04:23
  • It's a superset of C, unlike C++, which is not a superset of C. – Dietrich Epp Aug 06 '11 at 04:32
  • @mcandre: I guess as other have suggested, the best thing to do is to separate the files in different folders – Amro Aug 06 '11 at 13:10