Skip to content

Instantly share code, notes, and snippets.

@Benedikt1992
Last active May 26, 2018 12:29
Show Gist options
  • Save Benedikt1992/05d01948ed1638e656b1dfbad244337c to your computer and use it in GitHub Desktop.
Save Benedikt1992/05d01948ed1638e656b1dfbad244337c to your computer and use it in GitHub Desktop.
External Header example
#ifndef SAMPLE_CONF_H
#define SAMPLE_CONF_H
#define FIRST_MACRO 1
#endif //SAMPLE_CONF_H
#ifndef SAMPLE_HELLO_CITY_H
#define SAMPLE_HELLO_CITY_H
#define SECOND_MACRO 1
#endif //SAMPLE_HELLO_CITY_H
#include "hello_city.h"
#include "hello_world.h"
#include <stdio.h>
#if FIRST_MACRO
#if SECOND_MACRO
void hello_world(void) {
printf("Hello, World!\n");
}
#endif //SECOND_MACRO
#endif //FIRST_MARCO
#ifndef FIRST_MACRO
void hello_world(void) {
printf("Shame on you!\n");
}
#endif
//
// Created by username on 5/26/18.
//
#ifndef SAMPLE_HELLO_WORLD_H
#define SAMPLE_HELLO_WORLD_H
/* PROJECT_CONF_H might be defined in the project Makefile */
#ifdef PROJECT_CONF_H
#include PROJECT_CONF_H
#endif /* PROJECT_CONF_H */
void hello_world();
#endif //SAMPLE_HELLO_WORLD_H
#include <stdio.h>
#include "hello_world.h"
int main() {
hello_world();
return 0;
}
main: main.o hello_world.o
gcc -o main main.o hello_world.o
rm *.o
main.o: main.c hello_world.h
gcc -c main.c
hello_world.o: hello_world.c hello_world.h hello_city.h
gcc -DPROJECT_CONF_H=\"conf.h\" -c hello_world.c
clean:
rm main
all: main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment