gpt4 book ai didi

c - DLL 隐式链接

转载 作者:太空宇宙 更新时间:2023-11-04 01:30:47 26 4
gpt4 key购买 nike

我无法将 DLL 隐式链接到 C 控制台应用程序。我使用 Visual Studio 2008。

我创建了一个空的 DLL 项目“Library”,它只包含一个文件 main.c:

__declspec(dllexport) int get_value()
{
return 123;
}

我还使用文件 main.c 创建了空的控制台项目“CallingProgram”:

__declspec(dllimport) int get_value();

void main()
{
int result = get_value();
}

我将“Library.lib”添加到“Linker\Input\Additional Dependencies”。

我仍然有这个错误:

error LNK2019: unresolved external symbol __imp__get_value referenced in function _main

我测试了使用 LoadLibrary/GetProcAddress 创建的 DLL - 它工作正常。

我使用 DumpBin 检查了 Library.dll,它看起来也不错:

Microsoft (R) COFF/PE Dumper Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.


Dump of file library.dll

File Type: DLL

Section contains the following exports for Library.dll

00000000 characteristics
5340072C time date stamp Sat Apr 05 17:37:48 2014
0.00 version
1 ordinal base
1 number of functions
1 number of names

ordinal hint RVA name

1 0 00011109 get_value = @ILT+260(_get_value)

Summary

1000 .data
1000 .idata
2000 .rdata
1000 .reloc
1000 .rsrc
4000 .text
10000 .textbss

请帮助我了解缺少的内容!

最佳答案

1 0 00011109 get_value

符号没有正常的装饰。它通常是 _get_value,所有 cdecl 函数都有一个前导下划线。使用 __declspec(dllexport) 还提供了 __imp_get_value 导出。它是一个优化绑定(bind)的函数指针。

但这并没有发生,您一定在您的库项目中使用了 .def 文件。哪些重命名导出函数。没关系,但是现在您的 __declspec(dllimport) 不兼容,DLL 不再导出 __imp_ 函数指针。链接器提示,因为它找不到导入库。

通过从库项目中删除 .def 文件(最好)或从 exe 项目的声明中删除 __declspec(dllimport) 属性来解决此问题。强烈建议编写一个 .h 文件来声明 DLL 中的导出函数。

关于c - DLL 隐式链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22882064/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com