Почему происходит ошибка линковки , используя makefile?

У меня есть 3 файла:

1. hellomake.c

#include <hellomake.h>

int main() {
  // call a function in another file
  myPrintHelloMake();

  return(0);
}

2. hellofunc.c

#include <stdio.h>
#include <hellomake.h>

void myPrintHelloMake(void) {

  printf("Hello makefiles!\n");

  return;
}

3. hellomake.h

/*
example include file
*/

void myPrintHelloMake(void);

Все файлы hellomake.c,hellofunc.c,hellomake.h хранятся в папке src. Я хочу получить объектные .o файлы и сохранить их в папке obj, то есть сделать только этап компиляции. (Это нужно мне за тем,чтобы потом их слинковать в статическую библиотеку). Вот так выглядит makefile:

CC=gcc

ODIR=obj

_DEPS = hellomake.h 

_OBJ = hellomake.o hellofunc.o 
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))


$(ODIR)/%.o: %.c $(_DEPS)
    $(CC) -c -o $@ $< -I.

hellomake: $(OBJ)

.PHONY: clean

clean:
    rm -f $(ODIR)/*.o *~ 

Но я ловлю вот такую ошибку:

elvin@ubuntu:~/GuideToLinkers/example5/src$ make hellomake 
gcc -c -o obj/hellomake.o hellomake.c -I.
gcc -c -o obj/hellofunc.o hellofunc.c -I.
gcc     hellomake.c obj/hellomake.o obj/hellofunc.o   -o hellomake 
obj/hellomake.o: In function `myPrintHelloMake':
hellomake.c:(.text+0x0): multiple definition of `myPrintHelloMake'
/tmp/ccGYJPJd.o:hellomake.c:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'hellomake' failed
make: *** [hellomake] Error 1

Помогите разобраться, я хочу получить только объектные файлы, поэтому эта строчка мне не нужна - gcc hellomake.c obj/hellomake.o obj/hellofunc.o -o hellomake


Ответы (0 шт):