Recently encountered on the compilation of the "unresolved external symbol" problem, in the online search for a solution to do = Find the following blog content, the author explained quite comprehensive, as a collection for future inquiries.
Original http://blog.csdn.net/shenyulv/article/details/6699836
VC + + often encounter link error LNK2001, this error is very annoying, because for programmers, it is better to change the error than compile errors, and in general, when a connection error occurs, the compilation has passed. There are many reasons for connection errors, especially LNK2001 errors, which are often unclear. If you do not learn and understand VC + +, to correct the connection error LNK2001 very difficult. Beginners in the process of learning VC + +, encountered LNK2001 error message is mainly: unresolved external symbol "symbol" (Indeterminate external "symbol"). This error message is generated if the connector cannot find the referenced function, variable, or label in all libraries and destination files. In general, there are two reasons for an error: One is the referenced function, the variable does not exist, is spelled incorrectly, or an error is used, and then a different version of the connection library may be used.
The following are the possible causes of LNK2001 errors:
A LNK2001 caused by a coding error.
1. does not match the program code or module definition (. DEF) file can cause LNK2001. For example, if you declare a variable "var1" within a C + + source file and try to access the variable as a variable "VAR1" within another file, the error occurs.
2. If the inline function used is in the. The definition within the CPP file, rather than within the header file, will result in a LNK2001 error.
3. LNK2001 is generated when the function is called when the parameter type used does not match the type of the function declaration.
4. Attempting to invoke a virtual function from a constructor or destructor of a base class will cause LNK2001.
5. Be aware of the common nature of functions and variables, only global variables, functions can be common. static functions and static variables have the same usage scope restrictions. Attempting to access any static variable that is not declared within the file from outside the file causes a compilation error or LNK2001. Variables declared within a function (local variables) can only be used within the scope of the function. The global constants of C + + have only static connection performance. This is different from C, which can also produce LNK2001 errors if you try to use global variables in multiple files in C + +. A workaround is to include the initialization code for the constant in the header file when needed, and in the. CPP file, and another method is to assign a constant to the variable when it is used.
Two LNK2001 caused by compilation and linked settings
1. If the/nod (/NODEFAULTLIB) option is used at compile time, the runtime and MFC libraries required by the program are written to the target file module by the compiler when connected, but these libraries are not linked to the project file unless they are explicitly included in the file. Using/nod in this case will cause error LNK2001.
2. If you do not set a program entry for wWinMainCRTStartup, you will get the LNK2001 error message "unresolved external on [email protected]" When using Unicode and MFC.
3. When compiling with the/MD option, since all runtimes are kept within the dynamic-link library, references to "Func" in the source file are references to "__imp__func" in the target file. If you attempt to connect using static LIBC.LIB or LIBCMT.LIB, LNK2001 will occur on the __imp__func, and/MD will occur if you do not compile with the MSVCxx.LIB option.
4. When compiling with the/ML option, LNK2001 occurs on _errno if the LIBCMT.LIB link is used.
5. When compiling a debug version of an application, it also generates LNK2001 if the connection is made with a release modal library, and the same problem arises when connecting to the release application using the debug version of the modal library.
6. Mixed use of different versions of libraries and compilers can also cause problems because the new version of the library may contain symbols and descriptions that were not previously available.
7. The use of inline and non-inline compilation options in different modules can cause LNK2001. If you open a function inline (/ob1 or/OB2) when you create a C + + library, but you close the function inline (without the inline keyword) in the corresponding header file that describes the function, you get the error message. To avoid this problem, you should flag inline functions with the inline keyword in the corresponding header file.
8. Incorrect/subsystem or/entry settings can also cause LNK2001.
In fact, there are many reasons for LNK2001, the above reasons are only part of it, for beginners This is enough to understand for a while. However, the purpose of the analysis of the cause of the error is to avoid errors LNK2001 errors, although it is difficult, but as long as the attention of the above problems, can be avoided and resolved.
Error LNK2001 Several cases of unresolved external symbols and their solutions