title: Weird error " multiple definition of `xxx` " while compiling C++ project
body: <p>When I try to compile my C++ project  via my Makefile I keep getting errors like those:</p>
  
  <pre><code>Server.o: In function `Bot::getRandomMessage()':
  /home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:18: multiple definition of `Bot::getRandomMessage()'
  Bot.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:18: first defined here
  Server.o: In function `Bot':
  /home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:27: multiple definition of `Bot::Bot()'
  Bot.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:27: first defined here
  Server.o: In function `~Bot':
  /home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:30: multiple definition of `Bot::~Bot()'
  Bot.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:30: first defined here
  Server.o: In function `~Bot':
  /home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:30: multiple definition of `Bot::~Bot()'
  Bot.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:30: first defined here
  Server.o: In function `~Bot':
  /home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:30: multiple definition of `Bot::~Bot()'
  Bot.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:30: first defined here
  Server.o: In function `Bot::getName()':
  /home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:33: multiple definition of `Bot::getName()'
  Bot.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:33: first defined here
  Server.o: In function `ChatRoom::getCurrentTime()':
  /home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Server.cpp:74: multiple definition of `ChatRoom::getCurrentTime()'
  main.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Server.cpp:74: first defined here
  Server.o: In function `Bot::getRandomMessage()':
  /home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Bot.cpp:18: multiple definition of `vectorOfThreads'
  main.o:/home/ubuntu/NetBeansProjects/SemestralniPraceChat/./Server.cpp:74: first defined here
  Server.o: In function `Bot::getRandomMessage()':
  </code></pre>
  
  <p>I'm quite confused with that.. When I compile it directly with the command 
  <code>g++ main.cpp -Wall -pedantic -Wno-long-long -O0 -ggdb -lncurses -pthread -o AppName</code> , then it doesn't produce any error. So I expect, that the error appears somewhere in my <code>Makefile</code></p>
  
  <pre><code>#macros
  Remove=rm -rf
  Doxygen=Doxyfile
  RUN=./dvoram64
  FLAGS=-Wall -pedantic -Wno-long-long -O0 -ggdb -pthread -lncurses -g
  OBJECTS=main.o Bot.o Server.o Client.o GrumpyBot.o JokerBot.o WeatherBot.o DummyBot.o
  
  #generates final binary and documentation
  all:    $(Doxygen)
      make compile
  
  #build into final binary
  compile: $(RUN)
  
  #run program
  run:    
      make link
      $(RUN)
      $(RUN)
  
  
  clean:
      $(Remove) dvoram64
      $(Remove) $(OBJECTS)
  
  #generate documentation in '&lt;login&gt;/doc' folder
  doc: $(Doxygen) /*
      ( cd ./ | doxygen $(Doxygen))
  
  link: $(OBJECTS)
      g++ $(OBJECTS) -lncurses -pthread -o dvoram64
  
  #rules how to compile into the executalble file
  $(RUN): $(OBJECTS)
  
  Bot.o: ./Bot.cpp ./Bot.h
      g++ $(FLAGS) -c ./Bot.cpp
  
  DummyBot.o: ./DummyBot.cpp ./DummyBot.h ./Bot.h
      g++ $(FLAGS) -c ./DummyBot.cpp
  
  GrumpyBot.o: ./GrumpyBot.cpp ./GrumpyBot.h ./Bot.h
      g++ $(FLAGS) -c ./GrumpyBot.cpp
  
  JokerBot.o: ./JokerBot.cpp ./JokerBot.h ./Bot.h
      g++ $(FLAGS) -c ./JokerBot.cpp
  
  WeatherBot.o: ./WeatherBot.cpp ./WeatherBot.h ./Bot.h
      g++ $(FLAGS) -c ./WeatherBot.cpp
  
  Client.o: ./Client.cpp
      g++ $(FLAGS) -c ./Client.cpp
  
  
  main.o: ./main.cpp 
      g++ $(FLAGS) -c ./main.cpp
  
  Server.o: ./Server.cpp ./Bot.h ./JokerBot.h ./WeatherBot.h ./GrumpyBot.h ./DummyBot.h
      g++ $(FLAGS) -c ./Server.cpp
  </code></pre>
  
  <p>Could anybody please explain me, what causes this error and show me, how to fix it?</p>