Skip to content

Instantly share code, notes, and snippets.

@pcyu16
Last active December 18, 2015 17:49
Show Gist options
  • Select an option

  • Save pcyu16/5820782 to your computer and use it in GitHub Desktop.

Select an option

Save pcyu16/5820782 to your computer and use it in GitHub Desktop.
Simple example for multiple file compilation in C
/**
* 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");
}
/**
* File: foo.h
* Description: foo function declaration
* Author: pcyu16
*/
#ifndef FOO_H
#define FOO_H
// function declaraion
void foo(void);
#endif
/**
* 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;
}
# 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