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.
1 Answers
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.

- 1
- 1

- 11,636
- 6
- 33
- 71
-
Thanks. Nice Explanation. But I'm getting public: virtual struct QMetaObject const * __thiscall UpdateDialog::metaObject(void)const as a unresolved external symbol i don't know, which lib/header is the source of this external symbol. – Hage sumne Oct 29 '14 at 14:10
-
@Hagesumne Well, that signals that you have some QT stuff in the code, are you linking against QT libraries? – Rudolfs Bundulis Oct 29 '14 at 14:11
-
How can I know whether i'm linking against Qt libraries or not? – Hage sumne Oct 29 '14 at 14:18
-
@Hagesumne Do you have QtCore4.lib (this is an example, I guess for QT 5 it wil have other name) in your linker inputs? – Rudolfs Bundulis Oct 29 '14 at 14:28
-
Yes. I have QtCore4.lib in my linker input. – Hage sumne Oct 29 '14 at 14:33
-
Qt5Core.lib for Qt 5. – Hage sumne Oct 29 '14 at 14:36
-
@Hagesumne not 100% sure but try adding QtGui5.dll – Rudolfs Bundulis Oct 29 '14 at 14:47
-
@Hagesumne Ahh btw, you should find hich file the UpdateDialog class resides in and then there should be a file called moc_
.cpp, this one should be added to the solution too. If there is no such file you must either use the Qt moc tool to generate on or use Visual Studio QT plugin to automate this. – Rudolfs Bundulis Oct 29 '14 at 14:50