Links that are often encountered by VC ++ LLNK2001

zhaozj2021-02-16  78

When you learn VC , you will often encounter a link error LNK2001. This error is very annoying because

For the programmer, the best change is more compiled, and when the connection error occurs,

Compiled is passed. There are very many reasons for generating connection errors, especially LNK2001 errors, often

Ming it happened. If you don't learn and understand VC in depth, you want to correct the connection error LNK2001

It is often difficult.

In the process of learning VC , the beginner is mainly:

Unresolved External Symbol "Symbol" (Uncertain external "symbol").

If the connection program does not find the referenced function, variables, or in all libraries and destination files.

The label will generate this error message. In general, there are two reasons for errors: one is referenced

The function, the variable does not exist, spelling incorrectly or using errors; secondly versions may be used

Connection library.

The following is the 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. E.g,

If a variable "var1" is declared within the C source file, it is attempted to change in another file.

"VAR1" accesses the variable, which will happen.

2. If the inline function used is defined in the .cpp file, not on the header file

Rightening will cause the LNK2001 error.

3. When the function is called, if the type of parameter type used with the function declaration does not match the type of function declaration.

LNK2001.

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 from the external access

Any compilation error or LNK2001 will be caused when there will be no static variables declared within the file.

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, if trying to be in C

LNK2001 errors are generated in multiple files. A solution is needed

The initialization code of this constant is added to the header file, and the header file is included in the .cpp file; another

The method is to assign the variable to constant when used.

two. LNK2001 due to compilation and link settings

1. If you use the / nod (/ nodefaultlib) option, the run needs to run

The library and the MFC library are written to the target file module when the compiler is connected, unless it is clearly included in the file.

These libraries, otherwise these libraries will not be linked into project files. In this case, use / NOD will guide

To the error LNK2001.

2. If there is no program entry for WwinmainCrtStartup, using Unicode and MFC

The LNK2001 error message of "Unresolved External On _winmain @ 16" will be obtained.

3. When using the / md option, since all runners are kept within the dynamic link library,

The reference to "FUNC" in the source file is referenced to "__Imp__func" in the target file.

If you try to use a static library libc.lib or libcmt.lib, it will be sent on __Imp__func.

LNK2001; if you do not use the / md option to compile, LNK2001 will also occur when using the MSVCXX.LIB connection.

4. When compiling using the / ml option, if you use the libcmt.lib link to occur on _ERRNO on _ERRNO. When you compile the debug version of the application, if you use the distribution modal library to connect

LNK2001; Similarly, use the debug version of the modal library to connect the distribution application to the same

problem.

6. The mixing use of different versions of libraries and compilers can also produce problems, because the new version of Curre

Can contain symbols and descriptions that have not been issued earlier.

7. Use the inline and non-inline compilation options in different modules to cause the LNK2001. in case

When you create a C library, the function inline (/ OB1 or / OB2) is turned on, but the corresponding head describing the function

The file is closed in the function inline (no inline keyword), and this error message will be obtained.

To avoid the occurrence of this problem, the inline keyword flag should be used in the corresponding header file.

8. Incorrect / subsystem or / entry settings can also cause the LNK2001.

In fact, there are still many reasons for the production of LNK2001, and the above reasons are only part,

Scholars say these are enough to understand a while. However, the purpose of analyzing the cause of the error is to avoid mistakes

Erroading. Although the LNK2001 error is more difficult, as long as the above problem is noted,

Avoid and solve it.

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

New Post(0)