VC ++ link error LNK2001

zhaozj2021-02-16  44

VC link error LNK2001

(Tianjin Housing Super) When you learn VC , you will often encounter a link error LNK2001. This error is very annoying, because for the programmer, the best change error is more compiled, and when the connection error occurs, it has been compiled. by. There are very many reasons for generating connection errors, especially the LNK2001 is wrong, often unknown. If you don't learn and understand VC in depth, you want to correct the connection error. LNK2001 is very difficult. In the process of studying VC , the beginner is mainly: unresolved external symbol "Symbol" (Uncertain external "symbol"). This error message will be generated if the connection program cannot find the referenced functions, variables, or tags in all libraries and destination files. In general, there are two reasons for incorrect: First, the variables are not existed, spelling is incorrect, using errors; secondly, different versions of connection libraries may be used. The following is a cause of the LNK2001 error: one. The LNK2001 caused by the encoded error. 1. Unpredictable program code or module definition (.def) file can cause LNK2001. For example, if a variable "var1" is declared within the C source file, it is attempted to access the variable in the variable "var1" in another file. 2. If the inline function used is defined within the .cpp file, not the definition within the header file will cause the LNK2001 error. 3. When the function is called, if the type of parameter type with the function declaration does not match the function declaration, LNK2001 will be generated. 4. Trying to call the virtual function from the constructor or description function of the base class. The LNK2001 will be caused. 5. Pay attention to the publicity of functions and variables, only global variables, functions are public. Static functions and static variables have the same range limit. When trying to access any static variables not declared within the file from the file, it will cause compilation errors or LNK2001. Variables (local variables) declared within functions can only be used within the range of this function. The global constant of C has only static connection performance. This is different from C, and the LNK2001 error will also be generated if the global variable is used in multiple files of C . One solution is to add the initialization code of the constant in the header file, and contain the header file in the .cpp file; another method is used to assign the variable to the constant. Two. The LNK2001 1 caused by the settings of compilation and links. If the / nod (/ nodefaultlib) option is used, the runtime and MFC library required by the program are written to the target file module when the compiler is connected, unless these libraries are not included in the file. Will be linked into the project file. In this case, the use / NOD will result in an error LNK2001. 2. If there is no program entry for WwinMainCrtStartup, "UnreSolved External ON _WINMAIN @ 16" will be obtained when using Unicode and MFC, and will get the LNK2001 error message. 3. When compiling using the / md option, since all the runners are retained within the dynamic link library, "FUNC" is referenced in the source file, the reference to "__Imp__func" in the target file. If you try to use a static library libc.lib or libcmt.lib, LNK2001 will occur on __Imp__func; if you do not compile / MD option, LNK2001 will occur when using the MSVCXX.LIB connection.

转载请注明原文地址:https://www.9cbs.com/read-24341.html

New Post(0)