I'm new to visual studio win32/VC++ application development. I just want to know how the .obj files are generated and how can we solve the unresolved external symbols found in the .obj file.
Object files contain relocatable machine code that is generated from your source code. Visual Studio creates one .obj
file per each .cpp
file. Then depending on the project (executable, static/dynamic library) you can get relocatable or non-relocatable code. If code is relocatable then the symbols (function calls, variables) that are not available at the compilation time are marked as unresolved and when you link something that performs the relocation (for example an executable file) you get unresolved reference errors if other inputs do not provide the unresolved symbols. To solve these issues you must either provide the inputs in of object files that contain them (for example when your application has some global functions which other libraries used in your project depend on) or link against external libraries when you include their headers.
Unresolved symbols issues most often occur when one includes header files from either OS specific API or a 3rd party library and is not aware what to link against. The rule of a thumb is if you use 3rd party libraries specify them as additional linker inputs, if you use a OS API look for the documentation to see what you should link against (for example MSDN always states the libraries needed for each function). Of course you might use a library built by other person that does have some dependencies of it's own, and then you can get into these issue even without explicit introduction of any outside headers or libraries. In that case it is wise too find information on how that library was built and what where the dependencies - then you can either find and provide pre-built binaries or in the worst case build the dependencies your self and provide them as linker inputs.
I've written an answer about tackling unresolved symbols here that could be relevant.