130 likes | 285 Views
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.
E N D
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
Step 1a: open new files palindrome.c palindrome.h ask_palindrome.c #include <stdio.h> #include <string.h> int palindrome(...) { ... } int reverse(...) { ... } int main(...) { ... }
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(...) { ... }
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(...) { ... }
Step 2a: open new files reverse.c reverse.h palindrome.c #include <string.h> #include “palindrome.h” int palindrome(...) { ... } int reverse(...) { ... }
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(...) { ... }
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
Step 3: revise ask_reverse.c #include <stdio.h> #include <string.h> #include “reverse.h” int reverse(...) { ... } int main(...) { ... }
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