在 Visual Studio 2005 中创建 DLL

发布于 2024-07-27 17:33:05 字数 429 浏览 8 评论 0原文

我正在开发一个 C++ 库,我想将其传递给我的团队。 该库只有一个类和一堆方法。

因此,我开发了类定义文件(X.cpp)和相应的类声明文件(Xh)。

这是我的问题 -

  1. 在 Visual Studio 2005 中,将此库构建为 DLL 的最直接方法是什么,这样我可以获得以下文件: X.lib :我可以将其传递给我的团队,以便他们可以链接到我的库 X.dll:我可以将其传递给我的团队进行运行时

  2. 我应该使用静态库方式而不是 DLL 吗? 如果是这样,我该如何在 Visual Studio 2005 和 Visual Studio 2005 中执行此操作? 这会给我一个可以传递给我的团队的 X.lib 文件吗?

非常欢迎任何解释或参考。

非常感谢。

I am developing a C++ library that I want to pass on to my team. The library has just one class with a bunch of methods.

So, I have developed the class definition file (X.cpp) and a corresponding class declaration file (X.h).

Here are my questions --

  1. In Visual Studio 2005, whats is the most straight forward way to build this library as a DLL, such that I get the following files:
    X.lib : which I can pass to my team so they can link against my library
    X.dll : which I can pass to my team for run-time

  2. Instead of a DLL, should I rather be going the static library way ?? If so, how do I go about doing this in Visual Studio 2005 & will this give me a X.lib file that I can pass on to my team ?

Any explanations or references are very welcome.

Thank you very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你怎么这么可爱啊 2024-08-03 17:33:05

构建 DLL 最简单的方法是新建 -> 项目 -> Win32 控制台应用程序。 然后在对话框中选择 DLL 并选择“导出符号”。 这将合成一个带有 .h 和 .cpp 文件的 dll,演示如何导出类。 您可以摆脱这个 .h/.cpp,但首先导入您的类并添加适当的 #ifndef 语句。 现在就 DLL 与静态库而言,如果它是一个小类,并且不会经常改变,那么您可能会更好地使用静态库,它简单、简洁,它不会添加另一个需要提供的依赖项与您的产品。 如果 .cpp 文件中的代码经常更改(即函数实现),则 DLL 是很好的选择,因为您可以直接交换新的 DLL。

The easiest way to build a DLL, is New->Project->Win32 Console Application. Then on the dialog select DLL and select "Exports Symbols". This will synthesize a dll with a .h, and .cpp file which demonstrate how to export your classes. You can get rid of this .h/.cpp but first import your class add the appropriate #ifndef statements. Now as far as DLL versus Static library if its a single small class, that doesn't change particularly often you might be better off with a static library, its simple, its concise, it doesn't add another dependency which needs to be shipped with your product. A DLL is nice if the code in the .cpp file changes often (ie. the function implementations) because you can just swap in the new DLL.

高跟鞋的旋律 2024-08-03 17:33:05

从您的描述来看,您似乎已经有一个 Visual C++ 项目(如果我错了,请纠正我)。 如果是这样,当您进入项目属性时,在“常规”下您可以找到“配置类型” - 根据需要将其切换为“静态库”或“动态库”。

如果您选择“静态库”,那么您将只获得一个可以立即使用的.lib 文件。

如果您选择“动态库”,并且从 DLL 中导出任何函数(例如,通过用 __declspec(dllexport) 标记它们),将自动生成导出 .lib。

如果不知道您正在做什么的具体情况,很难判断哪个选项更可取。 一般来说,我建议默认使用静态库,因为它通常足够好,并且在处理 DLL(尤其是导出 C++ 符号的 DLL)时有更多陷阱。

From your description, it looks like you already have a Visual C++ project (correct me if I'm wrong). If so, when you go into project properties, under "General" you can find "Configuration Type" - switch it to "Static library" or "Dynamic library" as needed.

If you choose "Static library", then you will just get a .lib file that can be immediately used.

If you choose "Dynamic library", and you export any functions from your DLL (e.g. by marking them with __declspec(dllexport)), an export .lib will be generated automatically.

It's hard to tell which option is preferable without knowing the specifics of what you're doing. In general, I'd recommend defaulting to static libraries, because it's usually good enough, and there are more traps when dealing with DLLs (especially ones that export C++ symbols).

寄意 2024-08-03 17:33:05

我认为,在大多数情况下,dll 是比静态库更好的选择,因为当您分发新版本的库时,您的团队不必重新编译他们的代码。

I think that, in most cases, a dll is a better choice than a static lib because your team will not have to recompile their code when you distribute a new version of your library.

放赐 2024-08-03 17:33:05

有时我也遇到这个问题..因为我找不到C++项目属性中难以捉摸的设置..所以我决定为了自己的理智将其记下来,如博客文章

华泰

I struggle with this too sometimes.. because I can't find where the elusive setting is within C++ Project Properties.. So I decided to jot it down for my own sanity as a blog post.

HTH

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文