Error lnk20xx Link error

Source: Internet
Author: User
Introduction

This is often the case when you use vs to compile C ++ programs: the compilation is successful and no error is reported. However, an error is reported at the link, similar to: "error lnk2001! @ # ¥ @ % #...... @ # ¥ % & * & ¥ % ¥ @ # ¥ ". The related articles I found on the Internet are not the same as I actually encountered. Here I will summarize the solution to the Link errors I encountered. Note: The error code of error Lnk is not explicitly specified here.

1. XXX. Lib is not correctly configured.

Other DLL libraries such as XXX. dll are used for Windows compilation. Not only the. h header file is required, but also the corresponding XXX. Lib file is required. I have previously found that this XXX. Lib file specifies the function entry address, but why is it not needed in Linux?
Back to the problem itself, the XXX. Lib file is not correctly configured with the following possibilities:
A) the correct XXX. Lib is not written into the additional dependencies of the Link (or use # Param to be set in the program );
B) xxx. Lib does not exist in the path of the Search Library file (the Library file path is not set correctly );
C) The xxx. Lib file has multiple versions, and the version on the library file path is different from the version of your header file;

II. C ++ class functions are declared in the header file, but there is no corresponding definition in the CPP file.

This type of error is easy to find. The function name is displayed in the error.

Iii. Incorrect vs Configuration

This was just discovered, and I was tortured for half an afternoon yesterday.
A solution of our project contains multiple projects, and there is a dependency between projects. Some projects use lib generated by some basic projects.
For previous projects on vs2005, project dependencies are simple. You only need to right-click a project and select the project to be depended on from the project dependency menu.
A few days ago, I installed a new computer and migrated the project to vs2013. There are no problems with existing old projects. However, when creating a new project (with project dependencies), The Link error lnk2001 or error lnk2019 is always reported. After careful comparison of the differences between the new and old projects, and even conduct a diff check on the. vcxproj file, it is found that the project dependency in vs2013 should be set in General Properties> references. As in vs2005, it is impossible to set only the project dependencies. The specific discovery process is as follows:

  1. First, we eliminate the possibility that the second link error occurs in the previous summary. The Link error must be caused by the incorrect configuration of some items of the "connector" item on the project property page. Therefore, the old project and new project that can not be reported are compared one by one. Differences found on the "command line" tab:
    The items with no link errors in the/dynamicbase Item parameter have several more lines than those with errors. The red lines are marked as follows:

    The red line is the Lib generated by the project.

  2. Perform diff on the. vcxproj File
    The following configurations are added to a normally linked project:

    <ProjectReference Include="..\ENOService\ENOService.vcxproj">    <Project>{050ad614-2864-4ca2-b878-e16d2b07ed33}</Project>    <ReferenceOutputAssembly>false</ReferenceOutputAssembly>  </ProjectReference>  <ProjectReference Include="..\ENOUtils\ENOUtils.vcxproj">    <Project>{aa57406b-6277-443e-ba0b-8e782ee7ec07}</Project>    <ReferenceOutputAssembly>false</ReferenceOutputAssembly>  </ProjectReference>

The "projectreference include" part is the project on which the project depends.

  1. From the above two points, we can see that there is a problem with project dependencies.
    However, the project dependency has been configured. Where is the problem? Occasionally, click the first "common property" in the property card of the normally linked project-> "Reference ":

This item is blank in the project with a link error. Click "Add new reference" to set it and solve the problem!
After other projects are referenced here, the options in "project dependencies" in the right-click project cannot be deleted.

  1. Summary
    A) In essence, the problem is that Lib is not correctly configured -- the Lib file is not found.
    B) there have been many changes between vs2005 and vs2013, but the configuration of items not configured in 2005 is not counted as being in milliseconds? It can also be said that I did not keep up with the pace of MS, out ~
    C) ide vs plain text. IDE has done a lot of things for us. But we do not understand it (I am not good at understanding it ). If you write makefile yourself in Linux, you can clearly understand all the compiled configuration items of the project. Even when I open the. vcxproj file of Vs in a text editor, the configuration is clear at a glance. Now I am more and more inclined to plain text. Where can I modify the desired configuration of IDE as the version changes? It's okay.

Error lnk20xx Link error

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.