I am a java programmer; so I’m facing a lot of problems when it comes to c++ due to the linking stuff and so on. The problem basically is that I want to re-factor a single file (Transformation.cpp) into (TrasnformationBackend.cpp), (TrasnformationFrontend.cpp) and a header file. As you may see, I needed to declare a global struct through the all the files, and I did that using the “extern” in the header file and it works fine. However, unresolved external error appears when I try to move the frontend cpp file into a different directory.
By the way, I’m using BOOST.
An
externdeclaration in a header only tells the compiler that that variable will be defined in a compilation unit. It does not actually create that variable / allocate storage for it.If you have in your
.h:You need in one, and only one, of your
.cppfiles:Otherwise compilation will go ok, but link will fail because that external cannot be resolved.