Say I have this function called DoThis(const char *abc) in a file called one.cpp. So when I attempt to call this function from another function in a different source file (two.cpp), I get the error: error LNK2001: unresolved external symbol (C++), even though I used #include "one.h" What would I do to fix this?
That means that the definition of your function is not present in your program. You forgot to add that one.cpp
to your program.
What "to add" means in this case depends on your build environment and its terminology. In MSVC (since you are apparently use MSVC) you'd have to add one.cpp
to the project.
In more practical terms, applicable to all typical build methodologies, when you link you program, the object file created form one.cpp
is missing.
Sounds like you are using Microsoft Visual C++. If that is the case, then the most possibility is that you don't compile your two.cpp with one.cpp (one.cpp is the implementation for one.h).
If you are from command line (cmd.exe), then try this first: cl -o two.exe one.cpp two.cpp
If you are from IDE, right click on the project name from Solution Explore. Then choose Add, Existing Item.... Add one.cpp into your project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With