如何解决LNK2019错误 [英] How to solve error LNK2019

查看:370
本文介绍了如何解决LNK2019错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C ++发送一封简单的电子邮件.我从下面的链接下载了一个示例C ++程序. http://cboard.cprogramming.com/cplusplus-programming/125655-sending- simple-email-cplusplus.html 该示例程序在编译时似乎遇到以下错误.请帮我解决.

I am sending a simple email in C++. I downloaded a sample C++ program from the below link. http://cboard.cprogramming.com/cplusplus-programming/125655-sending-simple-email-cplusplus.html The sample program seems to hit the following error when it is compiling. Please help me with solution.

Error   8   error LNK2019: unresolved external symbol _send_mail referenced in function _wmain  

Error   9   error LNK2019: unresolved external symbol __imp__recv@16 referenced in function "int __cdecl connect_to_server(char const *)" (?connect_to_server@@YAHPBD@Z)    

Error   10  error LNK2019: unresolved external symbol __imp__connect@12 referenced in function "int __cdecl connect_to_server(char const *)" (?connect_to_server@@YAHPBD@Z) 

Error   11  error LNK2019: unresolved external symbol __imp__htons@4 referenced in function "int __cdecl connect_to_server(char const *)" (?connect_to_server@@YAHPBD@Z)    

Error   12  error LNK2019: unresolved external symbol __imp__socket@12 referenced in function "int __cdecl connect_to_server(char const *)" (?connect_to_server@@YAHPBD@Z)  

Error   13  error LNK2019: unresolved external symbol __imp__getprotobyname@4 referenced in function "int __cdecl connect_to_server(char const *)" (?connect_to_server@@YAHPBD@Z)   

Error   14  error LNK2019: unresolved external symbol __imp__gethostbyname@4 referenced in function "int __cdecl connect_to_server(char const *)" (?connect_to_server@@YAHPBD@Z)    

推荐答案

我遇到了相同的错误("LNK2019:无法解析的外部符号....").我的标头和调用已正确定义,并且仅在Debug模式下无法链接(在Release模式下没有投诉).原来,我的问题是由错误的.vcxproj文件引起的.

I encountered the same error ("LNK2019: unresolved external symbol ...."). My headers and calls were defined correctly, and it only failed to link in Debug mode (no complaints in Release mode). It turned out that my issue was caused by an incorrect .vcxproj file.

当我通过编辑vxcproj文件向项目中添加新的依赖项时,我犯了一个错误:我以为除了文件扩展名之外,这两个部分是相同的,因此我从第一个到最后一个<ItemGroup>(请参见下文).

When I added new dependencies to my project by editing the vxcproj file, I made a mistake: I thought that the two sections were identical except for the file extension, so I copy-pasted two lines from the first <ItemGroup> to the last <ItemGroup> (see below).

它有一段时间没有引起注意,因为我使用批处理脚本在 Release 模式下编译了代码.当我切换到 Debug 模式时,项目在链接阶段失败.最终,我发现了自己的错误,并通过以下修补程序解决了该问题:

It went unnoticed for a while, because I used a batch script to compile the code in Release mode. When I switched to Debug mode, the project failed at the linking stage. Ultimately, I discovered my error, and resolved the problem with the following patch:

-    <ClCompile Include="crypto/crypto.h" />
-    <ClCompile Include="crypto/rsa_public_key.h" />
+    <ClInclude Include="crypto/crypto.h" />
+    <ClInclude Include="crypto/rsa_public_key.h" />

.vcxproj文件的原始版本:

  <ItemGroup>
    ...
    <ClCompile Include="main.cpp" />
    <ClCompile Include="crypto/crypto.cpp" />
    <ClCompile Include="crypto/rsa_public_key.cpp" />
  </ItemGroup>
  <ItemGroup>
    <None Include="main.def" />
  </ItemGroup>
  <ItemGroup>
    ...
    <ClInclude Include="main.h" />
    <ClCompile Include="crypto/crypto.h" />
    <ClCompile Include="crypto/rsa_public_key.h" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>

底线:当您获得LNK2019并且互联网帮助上没有任何解释时,请检查项目设置.如果您使用版本控制,请将当前项目文件与已知良好的较旧版本进行比较.

Bottom line: When you get LNK2019 and none of the explanations on the internet help, check your project settings. If you use version control, compare the current project file with a known-good older version.

这篇关于如何解决LNK2019错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆