error LNK2005: already defined – C++

You either have to

  • move SetPersonName‘s definition to a .cpp file, compile and link to the resulting target
  • make SetPersonName inline

This is a well known case of One Definition Rule violation.

The static keyword makes the function’s linkage internal i.e. only available to the translation unit it is included in. This however is hiding the real problem. I’d suggest move the definition of the function to its own implementation file but keep the declaration in the header.

Leave a Comment