Blackhorse programmer 04-first knowledge of OC multi-file programming (3rd OC programs)

Source: Internet
Author: User

--- 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

  1. Compile: CC-C one. M two. m
  2. Link: CC one. O Two. O-framework Foundation

The one. O and two. O files must be linked at the same time.

  1. Run:./A. Out

(3) program analysis:

  1. The test function is declared in the two. h file (the Declaration is generally written in the. h header file ).
  2. The test function is defined in the two. M file.
  3. 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.

  1. 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.