In an attempt to have modular code, that is easy to maintain, I have split code from a previous VC++ solution into separate other projects. That was I can maintain the separate code bases, whilst still being able to include the working code in a solution. My solution explorer looks like this:
I have followed this (Project config/VC++/Extra Include paths) SO answer here, to allow fodHelperBypass.cpp
to access the methods within registry.cpp
. VS allows me to then import the header file for the RegistryTools project:
In fact, if I Ctrl + click
the registry.h
import declaration VS will open up the header file, and I can confirm it is being loaded from the correct location. In that same directory resides the registry.cpp
file.
I can also confirm that in the project build settings, both projects are set to an x64 build configuration (at an earlier point this was not the case, and VS could not locate registry.h
as RegistryTools build configuration was set to x86). VS also recognises the external functions within the fodHelper.cpp
file, and doesn't give any undefined error.
Yet when trying to build the project, I am receiving a LNK2019
error for each method declared in registry.h
and subsequently registry.cpp
.
I have read this SO post, but I don't feel as this applies, as I am not declaring any classes. Furthermore when I simply copied and pasted the registry.h
and registry.cpp
into the solutions directory, and added them to the solution, the code built without error.
Can someone please explain what I am doing incorrectly to cause this error with the linker?
EDIT
I have compiled the two subprojects involved in this solution as .lib
files, and that has had the desired effect. Although I am still confused, must I do this to be able to use methods from another C++ project? Must the referenced functions be part of a static library?
From reading the first link, I was under the impression that all I had to do was add the include directory in the project configuration, and then I would be able to use the methods from with RegistryTools.
RegistryTools is a project that contains one cpp file with four functions, and a header file that declares them.