Answer the question
In order to leave comments, you need to log in
How to fix C++ file linking error in VS 2017(LNK2005)?
Hey!
There was a problem in VS 2017 with a file linking error (LNK2005), I will attach screenshots for clarity.
There are 3 files in the project:
void solve() {
//
}
#include "source.cpp"
void solve();
Answer the question
In order to leave comments, you need to log in
1. *.h files should contain only function headers and declarations of global variables.
2. *.cpp files are not written in #includes (only *.h is written in them), *.cpp are compiled separately and then the resulting object files are linked together into one executable.
3. To avoid including the same file multiple times, use #ifndef:
// файл MyForm.h
#ifndef __MYFORM__
#define __MYFORM__
// здесь содержимое файла
#endif
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question