--- Java training, Android training, IOS training, and. Net training. We look forward to communicating with you! ---
1. Development of multiple. m Files
It is the same as developing multiple. c files in C.
(1) Compile three files
The one. m code is as follows:
1 // set two. h. The header file is copied to this 2 # import "Two. H "3 int main (INT argc, const char * argv []) 4 {5 // call test function 6 test (); 7 return 0; 8}
The two. H code is as follows:
1 // Declaration of the test function 2 void test ();
The two. m code is as follows:
1 // because the nslog function is used. h copy to this 2 # import <Foundation/Foundation. h> 3 // definition (implementation) of the test function 4 void test () 5 {6 nslog (@ "called the test function! "); 7}
(2) terminal commands
- Compile: CC-C one. M two. m
- Link: CC one. O Two. O-framework Foundation
The one. O and two. O files must be linked at the same time.
- Run:./A. Out
(3) program analysis:
- The test function is declared in the two. h file (the Declaration is generally written in the. h header file ).
- The test function is defined in the two. M file.
- CC one. O Two. O-framework Foundation
The two. O files must be linked at the same time. Because one. m lacks the definition of the test function, two. m lacks the definition of the main function.
- One. m introduces the two. h header file (with the declaration of the test function), so you can call the test function.
Blackhorse programmer 04-first knowledge of OC multi-file programming (3rd OC programs)