1 / 13

SEEM3460 Tutorial

SEEM3460 Tutorial. Multi-module programming in C. Create a working directory. Copy the material: mkdir ~/ c_multi cd ~seem3460/distribute/ c_multi -module cp -r ask ~/ c_multi Change directory: cd ~/ c_multi /ask. Framework 1. Target Structure. Step 1a: open new files.

dewei
Download Presentation

SEEM3460 Tutorial

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SEEM3460 Tutorial Multi-module programming in C

  2. Create a working directory • Copy the material: • mkdir ~/c_multi • cd ~seem3460/distribute/c_multi-module • cp -r ask ~/c_multi • Change directory: • cd ~/c_multi/ask

  3. Framework 1

  4. Target Structure

  5. Step 1a: open new files palindrome.c palindrome.h ask_palindrome.c #include <stdio.h> #include <string.h> int palindrome(...) { ... } int reverse(...) { ... } int main(...) { ... }

  6. Step 1b: link files palindrome.c palindrome.h ask_palindrome.c #include “palindrome.h” #include <stdio.h> #include <string.h> #include “palindrome.h” int palindrome(...) { ... } int reverse(...) { ... } int main(...) { ... }

  7. Step 1c: move code palindrome.c palindrome.h ask_palindrome.c #include <string.h> #include “palindrome.h” int palindrome(...) { ... } int reverse(...) { ... } int palindrome(...); int reverse(...); //the second line is temporary #include <stdio.h> #include <string.h> #include “palindrome.h” int palindrome(...) { ... } int reverse(...) { ... } int main(...) { ... }

  8. Step 2a: open new files reverse.c reverse.h palindrome.c #include <string.h> #include “palindrome.h” int palindrome(...) { ... } int reverse(...) { ... }

  9. Step 2b: link files reverse.c reverse.h palindrome.c #include “reverse.h” #include <string.h> #include “palindrome.h” #include “reverse.h” int palindrome(...) { ... } int reverse(...) { ... }

  10. Step 2c: move code reverse.c reverse.h palindrome.c palindrome.h #include <string.h> #include “reverse.h” int reverse(...) { ... } int reverse(...); #include <string.h> #include “palindrome.h” #include “reverse.h” int palindrome(...) { ... } int reverse(...) { ... } int palindrome(...); int reverse(...); //the second line is temporary

  11. Step 3: revise ask_reverse.c #include <stdio.h> #include <string.h> #include “reverse.h” int reverse(...) { ... } int main(...) { ... }

  12. Step 4: compile • Create .o files: • gcc -c reverse.c • gcc -c palindrome.c • gcc -c ask_palindrome.c • gcc -c ask_reverse.c • Link .o files as executables: • gcc -o ask_palindromeask_palindrome.opalindrome.oreverse.o • gcc -o ask_reverseask_reverse.oreverse.o

  13. Framework 2 (for your interest)

More Related