print_str.h
#ifndef __PRINT_STR_H__
#define __PRINT_STR_H__
void print_string(char *str);
#endif //__PRINT_STR_H__
print_str.c
#include <stdio.h>
#include "print_str.h"
void print_str(char *str)
{
printf("%s\n", str);
}
helloworld.c
#include <stdio.h>
#include "print_str.h"
int main()
{
print_str("hello world");
return 0;
}
Makefile
OBJS = helloworld.o print_str.o
CC=gcc
TARGET=helloworld
.PHONY: $(TARGET)
$(TARGET): $(OBJS)
$(CC) -o helloworld $(OBJS)
$(OBJS):%.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
.PHONY: clean
clean:
-rm -v *.o helloworld