Error lnk2019: unresolved external symbol ***** referenced in function *** Solution

Source: Internet
Author: User

When a function is declared in the header file but is not defined in the corresponding source file, an unresolved external symbol error occurs. In addition, when a function calls a function in an external library file but does not include the dependent library file in the properties of the current project, this error also occurs.

In summary, when a solution cannot find the definition of the involved function in linking, the "unresolved external symbol" error will occur.

For example, the following is a link error caused by the absence of mil. Lib.

1> linking...
1> mdispselect. OBJ: Error lnk2019: unresolved external symbol _ mappfree @ 4 referenced in function _ main
1> mdispselect. OBJ: Error lnk2019: unresolved external symbol _ msysfree @ 4 referenced in function _ main
1> mdispselect. OBJ: Error lnk2019: unresolved external symbol _ mdispfree @ 4 referenced in function _ main

[Solution]

1. Project-> ** properties...-> Configuration properties-> linker-> input-> additional dependencies-> mil. Lib

In addition, you also need to add the corresponding directory of the Mil library before: tools-> options-> projects and solutions-> VC ++ directories-> show directories for-> Add C: \ Program Files \ matrox imaging \ mil \ include and tools-> options-> projects and solutions-> VC ++ directories-> show directories for-> Add C: \ Program Files \ matrox imaging \ mil \ Lib. The purpose of adding a directory is to make Vc do not always use an absolute address when calling the corresponding library file. VC can search by file name in the contained directory. In this way, the previous mil. Lib does not need to use an absolute address.

[Disadvantage] Poor portability. If you copy the source and header files in the original project and re-create the project (for example, a program found on an e-book or on the Internet ), you still need to add directories and required library files in the project.

2. Add # pragma comment (Lib, "mil. lib") before the program to achieve the same effect.

[Advantage] avoids problems in solution 1.

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.