【问题标题】:Additional steps needed when linking a program to a DLL将程序链接到 DLL 时所需的其他步骤
【发布时间】:2014-11-30 03:21:30
【问题描述】:

我已经成功地使用本教程创建了一个引用 C++ DLL 的 C++ 可执行文件:http://programmingexamples.wikidot.com/blog:1

我是一名 .NET 开发人员。使用 .NET,您只需从控制台项目中添加对 DLL 的引用。使用 C++,您必须执行三个步骤(所有步骤都包含在链接中的第四步中)。我的问题是:

1) Why do you have to add the LIB as an Additional Dependency (step 4, part 1).  I believe it acts as a stub for the DLL, which is the skeleton.  This is not needed using .NET.
2) Step 4 (part 2) asks you to move the DLL to the same directory as the calling program.  Do you8 have to do this for every calling
program? I assume that if you add a reference to the DLL
(Properties/Common Properties/Add New Reference) that this step is not
needed?
3) Step 4(part 3) states that you must specify the location of the header files.  Why is this step needed if the header files are part of the DLL.  Is this because they are precompiled?

我知道 C++ 和 Visual Basic.NET/C#.NET 是两种完全不同的语言,但是我还不明白为什么需要这些额外的步骤。

【问题讨论】:

    标签: .net visual-c++


    【解决方案1】:
    1. 你可以在这里阅读关于 lib What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?

    "你不需要 .lib 文件来使用动态库,但没有 您不能将 DLL 中的函数视为您的 代码。相反,您必须手动调用 LoadLibrary 来加载 DLL(和 FreeLibrary 完成后),并 GetProcAddress 获取 DLL 中函数或数据项的地址。然后你必须施放 将返回的地址指向一个适当的函数指针,以便 使用它。”

    1. 您不必将 dll 移至可执行目录。您可以将其分配给 Windows 路径 http://www.computerhope.com/issues/ch000549.htm - 这是寻找 dll 的位置。

    2. 头文件类似于接口。它们包含函数的声明。 Why have header files and .cpp files in C++? "因此头文件是必要的,因为 C++ 编译器无法单独搜索符号声明,因此,您必须通过包含这些声明来帮助它。"

    【讨论】:

      猜你喜欢
      • 2019-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-24
      • 1970-01-01
      • 2023-01-26
      • 1970-01-01
      相关资源
      最近更新 更多