Last active
December 18, 2015 17:49
-
-
Save pcyu16/5820782 to your computer and use it in GitHub Desktop.
Simple example for multiple file compilation in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * File: foo.c | |
| * Description: foo function definition | |
| * Author: pcyu16 | |
| */ | |
| #include <stdio.h> | |
| #include "foo.h" | |
| /** | |
| * Display hello world message | |
| */ | |
| void foo(void) | |
| { | |
| printf("Hello World!!\n"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * File: foo.h | |
| * Description: foo function declaration | |
| * Author: pcyu16 | |
| */ | |
| #ifndef FOO_H | |
| #define FOO_H | |
| // function declaraion | |
| void foo(void); | |
| #endif | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * File: main.c | |
| * Description: main functiuon with only one function call | |
| * Author: pcyu16 | |
| */ | |
| #include <stdio.h> | |
| #include "foo.h" | |
| int main(void) | |
| { | |
| foo(); | |
| return 0; | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # File: Makefile | |
| # Description: Makefile for building the example | |
| # Author: pcyu16 | |
| CC=gcc | |
| OBJS=main.o foo.o | |
| CFLAGS=-Wall -Wextra | |
| all: program | |
| clean: | |
| rm -f program $(OBJS) | |
| program: $(OBJS) | |
| $(CC) $(CFLAGS) $(OBJS) -o program | |
| $(OBJS): main.c foo.c | |
| $(CC) $(CFLAGS) -c $*.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment