So I've been programming for a little while and I run into LNK errors all the time and just don't really know how to deal with them. Most often I get Unresolved external symbol
or '. . . ' was already defined in . obj
. This probably comes from how I include my header files. I have a header file and a matching cpp file and i include the header file anywhere where its needed. I dont know if thats ok to do. For example, I recently made a class with a static vector that I then included in several other . cpp files. Of course, I then immediately got an Unresolved external symbol error. Is there any proper way or rule to avoid these LNK2005
and LNK2019
mistakes.
Asked
Active
Viewed 11 times
0

Hydrated Dragon
- 58
- 6
-
You have the wrong idea. Include header files where ever you need them, these multiple definition link errors come from what you are putting in the header file. The static vector error is caused because you didn't define the static vector. Its a common mistake with static class members, beginners don't realise that they need to be defined as well as declared. – john Feb 08 '21 at 10:11
-
Of course there are proper rules to avoid these errors, but it's a bit too much to go through all the rules in a comment like this. Have a look at your C++ book, if your book doesn't cover this then get a [new book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – john Feb 08 '21 at 10:13