A summary of some link errors in C + + projects __c++

Source: Internet
Author: User

As a beginner, my biggest headache is Link's many mistakes. Many times, often always forget the problem is how to solve. So, let's write it down first.

1, error LNK2019: unresolved external symbols

	1>. If you are using a Third-party library, note that the function of viewing the error is declared in that header file, and then find its corresponding implementation library, copy it to your project project, or, if not in the debug directory, note the-> general-> of the property-> connector Add the Library directory to the additional library directory.
	    Then add #pragma comment (lib, "*.lib") to the project source code. Or add *.lib to the attribute-> Connector-> input-> additional dependencies.
	2>. If you are a function of your own implementation, make sure that you declare the function and implement it in the source file, and that the source file is added to your project (this is to compile the file and then generate this function into obj)
	In general, note that the issue is generally not defined by a statement.
	Also need to say is: When using the FFmpeg library, when the header file contains the library, you need to include the header file as follows, otherwise there will be a LNK2019 error:
		extern "C"
		{
			#include "libavformat/avformat.h"
		};
	The specific reason I personally think that it should be ffmpeg inside the implementation of the call C library, rather than C + + library, so in the inclusion of header file compilation, to specify the C library compiled. Do not know whether this is the case, if wrong, I hope the great God can guide the maze.
	3>, if the calling convention is different, can also cause LNK2019 this error.
		The calling convention is modified at the property->c/c++-> Advanced-> calling convention.
	2, Error LNK2005:
	    This kind of error is still relatively good to solve, the main is to repeat the definition.
	    Here you need to explain the use of extern, we all know this is used to throw the modified variable or function, in other files can use this variable or function.
But there is a misunderstanding about this understanding. Like what:
			extern int A;     		This is a statement.
			extern int a = 0; 	This is defined
if extern int a = 0 is written in a common header file; Then when multiple files contain this header file, the variable A is defined multiple times, causing a LNK2005 error.
Of course the function is the same,
			extern void Fun ();    This is a statement.
   			extern void Fun ()     //This is defined
			{
				......
			}	
So to resolve this type of error, you need to change the definition of the header file that is included multiple times to the declaration.
	3, Error LNK2001	is also a common error, the next time you encounter, then to update this blog


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.