Link Error

The following is a possible cause LNK2001 or LNK2019 link error

1, the lack of appropriate library file (lib). Usually appear on your use of third-party libraries, header files downloaded but forgot to load the library file, or library files into the appropriate directory to forget the. In the link -> Fill additional input function according to the lazy.

2, you write the function declaration header file also wrote a function definition cpp file, but still LNK2019 error.

  Possible causes: forget these two files added to the project.

3, you write the function declaration header file, also wrote a function defined cpp file also joined the project and determine the function body you're definitely in the library file, but still LNK2019 error.

  Possible causes: C language and C ++ language mixed, because C ++ supports function overloading, so the function name C ++ compiler-generated library file will be completely different, such as C compiler generates _readRegmark the function name, and the C ++ compiler generates a "void __cdecl readRegmark (char *)" (? readRegmark @@ YAXPAD @ Z) such a function name. When your function is written in C language, VS compiler will press the C language compiler rule, but the linker does not know foolishly went with the results of the function name C ++ rules can not find it. Solution: add the following code in the header file in the C language

. 1  #ifdef the __cplusplus
 2  extern  " C " {
 . 3  #endif 
. 4  
. 5  void readRegmark ( char * regmark);   // this write function declaration 
. 6  
. 7  #ifdef the __cplusplus
 . 8  }
 . 9  #endif

4, the template declaration and implementation to be placed in the same folder. Template function declaration and implementation files to a folder in the same file. Sometimes the parameter type of function declarations and definitions behind the front of the function is not the same, compile pass, but the link will appear LNK2019 error!

5, the inline function is defined in the header file (typically needs to be defined in cpp).

6, the wrong project type, and so on.

Guess you like

Origin www.cnblogs.com/ice-arrow/p/11084520.html