当包含**。h就足够了,添加.lib文件时是强制性的吗? [英] When include **.h is enough and when add a .lib file is mandatory?

查看:86
本文介绍了当包含**。h就足够了,添加.lib文件时是强制性的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我遇到了Linker问题而且我已经解决了,但我想知道何时必须采取这种方式来解决问题。

I had a Linker problem and I solved, but I want to know when I have to take this way to face a problem.

我在以下函数中遇到了链接器问题:

I had a linker problem with the following function:

BCryptOpenAlgorithmProvider

BCryptOpenAlgorithmProvider

在我包含文件bcrypt.h之前

before I had included the file bcrypt.h

#include< bcrypt.h>

#include <bcrypt.h>

编译后我收到链接错误:

after the compilation I receive the link error:

1>测试AES.obj:错误LNK2028:seris referenciaalsímbolo(token)sin resolver(0A000014)" extern"C" long __stdcall BCryptOpenAlgorithmProvider(void * *,wchar_t const *,wchar_t const *,unsigned long)" (?BCryptOpenAlgorithmProvider @@ $$ J216YGJPAPAXPB_W1K @ Z)
enlafunción" private:void __clrcall TestAES :: Form1 :: button1_Click(class System :: Object ^,class System :: EventArgs ^)" (?button1_Click @ Form1 @ TestAES @@ $$ FA $ AAMXP $ AAVObject @ System @@ P $ AAVEventArgs @ 4 @@ Z)

1>Test AES.obj : error LNK2028: se hace referencia al símbolo (token) sin resolver (0A000014) "extern "C" long __stdcall BCryptOpenAlgorithmProvider(void * *,wchar_t const *,wchar_t const *,unsigned long)" (?BCryptOpenAlgorithmProvider@@$$J216YGJPAPAXPB_W1K@Z) en la función "private: void __clrcall TestAES::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@Form1@TestAES@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)

问题只有在我添加文件时才解决,例如链接器输入的附加依赖项(Project-> properties-> Configurtion Property-> Linker-> Input-> Additional Dependency-> Edit)

The problem only was solved when I add the file like an additional Dependency for the linker input (Project->properties->Configurtion Property->Linker->Input->Additional Dependency->Edit)

为什么要发生这个?,当我必须添加lib文件时,何时不需要?

Why happend this?, when I have to add the lib file, and when is not needed?

推荐答案


AMG_CHILE,

感谢您在此处发帖。

>>为什么会发生这种情况?,当我必须添加时lib文件,何时不需要?

标题仅提供库(静态或动态)提供的函数的原型。\\声明。这允许编译器确定链接器可以访问哪些函数。静态库提供了
相同功能集的实现。因此,链接器可以解析对这些函数的引用。

The header only provides prototypes\declaration of the functions that the library (static or dynamic) provides. This allows the compiler to determine what functions the linker can expect to have access to. A static library provides the implementation of the same set of functions. So that the linker could resolve the references to these functions.

这是一个包含详细信息的案例关于编译和链接,你可以参考。

Here is a case contains detailed information about compiling and linking, you could refer to.

https://stackoverflow.com/questions/6264249/how-does-the-compilation-linking-process-work

希望这对你有所帮助。

最好的问候,

Baron Bi


这篇关于当包含**。h就足够了,添加.lib文件时是强制性的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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