title: Makfile generates both `(.text+0x0): multiple definition` and `(.text+0x44): undefined reference to` errors when linking .o objects
body: <p>I have the following makefile with which I cannot manage to link the objects into the final executable, although it builds the individual object files fine. It outputs both <code>(.text+0x0): multiple definition</code> and <code>(.text+0x44): undefined reference to</code> errors when building the main target.</p>
  <pre><code># Set compiler
  CC = gcc
  
  # Include headers 
  INC_HDR := -I. -IAPI/core -IAPI/platform
  
  # Define final executable 
  EXE := driver 
  
  # List source
  SRC := $(wildcard API/core/*.c) \
          $(wildcard API/platform/*.c) \
          main.c 
  
  # List headers
  HDR := $(wildcard API/core/*.h) \
          $(wildcard API/platform/*.h) 
  
  # Derive objects
  OBJ := $(patsubst %.c, %.o, $(SRC))
  
  # Set flags 
  CPPFLAGS := $(INC_HDR) -MMD -MP # -I is a preprocessor flag, not a compiler flag -MMD -MP
  CFLAGS   := -Wall           # some warnings about bad code
  LDFLAGS  := -L.             # -L is a linker flag
  LDLIBS   := -lm             # Left empty if no libs are needed
  
  .PHONY: all clean 
  
  all: $(EXE)
  
  $(EXE): $(OBJ) 
      @echo Linking $@
      $(CC) $(CPPFLAGS) $(CFLAGS) $(LDLIBS) $^ -o $@ 
  
  $(OBJ): $(SRC) $(HDR)
      @echo Building $@ 
      $(CC) $(CPPFLAGS) $(CFLAGS) -c $&lt; -o $@
  
  clean:
      @find . -type f -name '*.o' -delete
      @find . -type f -name '*.d' -delete
  </code></pre>
  <p>This question is quite close to other posts but I haven't been able to find what the problem is so far.</p>
  <p>As requested, the output of <code>make clean all</code> is:</p>
  <pre><code>Building API/core/VL53L1X_calibration.o
  gcc -I. -IAPI/core -IAPI/platform -MMD -MP  -Wall                -c API/core/VL53L1X_calibration.c -o API/core/VL53L1X_calibration.o
  Building API/core/VL53L1X_api.o
  gcc -I. -IAPI/core -IAPI/platform -MMD -MP  -Wall                -c API/core/VL53L1X_calibration.c -o API/core/VL53L1X_api.o
  Building API/platform/vl53l1_platform.o
  gcc -I. -IAPI/core -IAPI/platform -MMD -MP  -Wall                -c API/core/VL53L1X_calibration.c -o API/platform/vl53l1_platform.o
  Building main.o
  gcc -I. -IAPI/core -IAPI/platform -MMD -MP  -Wall                -c API/core/VL53L1X_calibration.c -o main.o
  Linking driver
  gcc -I. -IAPI/core -IAPI/platform -MMD -MP  -Wall                -lm              API/core/VL53L1X_calibration.o API/core/VL53L1X_api.o API/platform/vl53l1_platform.o main.o -o driver 
  API/core/VL53L1X_api.o: In function `VL53L1X_CalibrateOffset':
  VL53L1X_calibration.c:(.text+0x0): multiple definition of `VL53L1X_CalibrateOffset'
  API/core/VL53L1X_calibration.o:VL53L1X_calibration.c:(.text+0x0): first defined here
  API/core/VL53L1X_api.o: In function `VL53L1X_CalibrateXtalk':
  VL53L1X_calibration.c:(.text+0x170): multiple definition of `VL53L1X_CalibrateXtalk'
  API/core/VL53L1X_calibration.o:VL53L1X_calibration.c:(.text+0x170): first defined here
  API/platform/vl53l1_platform.o: In function `VL53L1X_CalibrateOffset':
  VL53L1X_calibration.c:(.text+0x0): multiple definition of `VL53L1X_CalibrateOffset'
  API/core/VL53L1X_calibration.o:VL53L1X_calibration.c:(.text+0x0): first defined here
  API/platform/vl53l1_platform.o: In function `VL53L1X_CalibrateXtalk':
  VL53L1X_calibration.c:(.text+0x170): multiple definition of `VL53L1X_CalibrateXtalk'
  API/core/VL53L1X_calibration.o:VL53L1X_calibration.c:(.text+0x170): first defined here
  main.o: In function `VL53L1X_CalibrateOffset':
  VL53L1X_calibration.c:(.text+0x0): multiple definition of `VL53L1X_CalibrateOffset'
  API/core/VL53L1X_calibration.o:VL53L1X_calibration.c:(.text+0x0): first defined here
  main.o: In function `VL53L1X_CalibrateXtalk':
  VL53L1X_calibration.c:(.text+0x170): multiple definition of `VL53L1X_CalibrateXtalk'
  API/core/VL53L1X_calibration.o:VL53L1X_calibration.c:(.text+0x170): first defined here
  /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
  (.text+0x20): undefined reference to `main'
  API/core/VL53L1X_calibration.o: In function `VL53L1X_CalibrateOffset':
  VL53L1X_calibration.c:(.text+0x44): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x5c): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x74): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x82): undefined reference to `VL53L1X_StartRanging'
  VL53L1X_calibration.c:(.text+0xa3): undefined reference to `VL53L1X_CheckForDataReady'
  VL53L1X_calibration.c:(.text+0xc0): undefined reference to `VL53L1X_GetDistance'
  VL53L1X_calibration.c:(.text+0xce): undefined reference to `VL53L1X_ClearInterrupt'
  VL53L1X_calibration.c:(.text+0xfa): undefined reference to `VL53L1X_StopRanging'
  VL53L1X_calibration.c:(.text+0x14f): undefined reference to `VL53L1_WrWord'
  API/core/VL53L1X_calibration.o: In function `VL53L1X_CalibrateXtalk':
  VL53L1X_calibration.c:(.text+0x1cf): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x1dd): undefined reference to `VL53L1X_StartRanging'
  VL53L1X_calibration.c:(.text+0x201): undefined reference to `VL53L1X_CheckForDataReady'
  VL53L1X_calibration.c:(.text+0x21e): undefined reference to `VL53L1X_GetSignalRate'
  VL53L1X_calibration.c:(.text+0x233): undefined reference to `VL53L1X_GetDistance'
  VL53L1X_calibration.c:(.text+0x241): undefined reference to `VL53L1X_ClearInterrupt'
  VL53L1X_calibration.c:(.text+0x26f): undefined reference to `VL53L1X_GetSpadNb'
  VL53L1X_calibration.c:(.text+0x2c3): undefined reference to `VL53L1X_StopRanging'
  VL53L1X_calibration.c:(.text+0x376): undefined reference to `VL53L1_WrWord'
  API/core/VL53L1X_api.o: In function `VL53L1X_CalibrateOffset':
  VL53L1X_calibration.c:(.text+0x44): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x5c): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x74): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x82): undefined reference to `VL53L1X_StartRanging'
  VL53L1X_calibration.c:(.text+0xa3): undefined reference to `VL53L1X_CheckForDataReady'
  VL53L1X_calibration.c:(.text+0xc0): undefined reference to `VL53L1X_GetDistance'
  VL53L1X_calibration.c:(.text+0xce): undefined reference to `VL53L1X_ClearInterrupt'
  VL53L1X_calibration.c:(.text+0xfa): undefined reference to `VL53L1X_StopRanging'
  VL53L1X_calibration.c:(.text+0x14f): undefined reference to `VL53L1_WrWord'
  API/core/VL53L1X_api.o: In function `VL53L1X_CalibrateXtalk':
  VL53L1X_calibration.c:(.text+0x1cf): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x1dd): undefined reference to `VL53L1X_StartRanging'
  VL53L1X_calibration.c:(.text+0x201): undefined reference to `VL53L1X_CheckForDataReady'
  VL53L1X_calibration.c:(.text+0x21e): undefined reference to `VL53L1X_GetSignalRate'
  VL53L1X_calibration.c:(.text+0x233): undefined reference to `VL53L1X_GetDistance'
  VL53L1X_calibration.c:(.text+0x241): undefined reference to `VL53L1X_ClearInterrupt'
  VL53L1X_calibration.c:(.text+0x26f): undefined reference to `VL53L1X_GetSpadNb'
  VL53L1X_calibration.c:(.text+0x2c3): undefined reference to `VL53L1X_StopRanging'
  VL53L1X_calibration.c:(.text+0x376): undefined reference to `VL53L1_WrWord'
  API/platform/vl53l1_platform.o: In function `VL53L1X_CalibrateOffset':
  VL53L1X_calibration.c:(.text+0x44): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x5c): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x74): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x82): undefined reference to `VL53L1X_StartRanging'
  VL53L1X_calibration.c:(.text+0xa3): undefined reference to `VL53L1X_CheckForDataReady'
  VL53L1X_calibration.c:(.text+0xc0): undefined reference to `VL53L1X_GetDistance'
  VL53L1X_calibration.c:(.text+0xce): undefined reference to `VL53L1X_ClearInterrupt'
  VL53L1X_calibration.c:(.text+0xfa): undefined reference to `VL53L1X_StopRanging'
  VL53L1X_calibration.c:(.text+0x14f): undefined reference to `VL53L1_WrWord'
  API/platform/vl53l1_platform.o: In function `VL53L1X_CalibrateXtalk':
  VL53L1X_calibration.c:(.text+0x1cf): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x1dd): undefined reference to `VL53L1X_StartRanging'
  VL53L1X_calibration.c:(.text+0x201): undefined reference to `VL53L1X_CheckForDataReady'
  VL53L1X_calibration.c:(.text+0x21e): undefined reference to `VL53L1X_GetSignalRate'
  VL53L1X_calibration.c:(.text+0x233): undefined reference to `VL53L1X_GetDistance'
  VL53L1X_calibration.c:(.text+0x241): undefined reference to `VL53L1X_ClearInterrupt'
  VL53L1X_calibration.c:(.text+0x26f): undefined reference to `VL53L1X_GetSpadNb'
  VL53L1X_calibration.c:(.text+0x2c3): undefined reference to `VL53L1X_StopRanging'
  VL53L1X_calibration.c:(.text+0x376): undefined reference to `VL53L1_WrWord'
  main.o: In function `VL53L1X_CalibrateOffset':
  VL53L1X_calibration.c:(.text+0x44): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x5c): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x74): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x82): undefined reference to `VL53L1X_StartRanging'
  VL53L1X_calibration.c:(.text+0xa3): undefined reference to `VL53L1X_CheckForDataReady'
  VL53L1X_calibration.c:(.text+0xc0): undefined reference to `VL53L1X_GetDistance'
  VL53L1X_calibration.c:(.text+0xce): undefined reference to `VL53L1X_ClearInterrupt'
  VL53L1X_calibration.c:(.text+0xfa): undefined reference to `VL53L1X_StopRanging'
  VL53L1X_calibration.c:(.text+0x14f): undefined reference to `VL53L1_WrWord'
  main.o: In function `VL53L1X_CalibrateXtalk':
  VL53L1X_calibration.c:(.text+0x1cf): undefined reference to `VL53L1_WrWord'
  VL53L1X_calibration.c:(.text+0x1dd): undefined reference to `VL53L1X_StartRanging'
  VL53L1X_calibration.c:(.text+0x201): undefined reference to `VL53L1X_CheckForDataReady'
  VL53L1X_calibration.c:(.text+0x21e): undefined reference to `VL53L1X_GetSignalRate'
  VL53L1X_calibration.c:(.text+0x233): undefined reference to `VL53L1X_GetDistance'
  VL53L1X_calibration.c:(.text+0x241): undefined reference to `VL53L1X_ClearInterrupt'
  VL53L1X_calibration.c:(.text+0x26f): undefined reference to `VL53L1X_GetSpadNb'
  VL53L1X_calibration.c:(.text+0x2c3): undefined reference to `VL53L1X_StopRanging'
  VL53L1X_calibration.c:(.text+0x376): undefined reference to `VL53L1_WrWord'
  collect2: error: ld returned 1 exit status
  makefile:33: recipe for target 'driver' failed
  make: *** [driver] Error 1
  </code></pre>