编译 C++ VS 的静态库和动态 dll 库

发布于 2024-12-03 03:38:24 字数 296 浏览 2 评论 0原文

我需要将现有的 C++ 库编译为 lib 和 dll,然后在不同的应用程序中使用静态和动态库。我用的是VS2010。

我不能做的是编辑所有头文件以便添加要导出的 __declspec(dllexport) 指令,因为库必须保持原样。

在Mac下我能够毫无问题地编译和使用dylib,但我知道VS在这方面有所欠缺。

在VS中,是否可以先编译静态库,然后再编译dll,以便“导出”函数(即在编译时可从应用程序链接)?换句话说,我可以像使用 __declspec(dllexport) 生成导出库一样使用静态库吗? 有更好的解决方法吗?

I need to compile an existing C++ library both as a lib and a dll, and then use the static and dynamic libraries in different applications. I use VS2010.

What I can't do is to edit all the header files in order to add __declspec(dllexport) instructions to export, as the library must be kept as it is.

Under Mac I was able to compile and use a dylib without problems, but I know that VS is lacking in this regard.

In VS is it feasible to compile a static lib first and then a dll in order to have functions "exported" (i.e. linkable from an application at compilation time)? In other words, can I use the static lib as if was the export lib generated with __declspec(dllexport)?
Are there better workarounds?

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

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

发布评论

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

评论(1

梦毁影碎の 2024-12-10 03:38:24

我需要将现有的 C++ 库编译为 lib 和 dll,并且
然后在不同的应用程序中使用静态和动态库。我
使用VS2010。

为此创建配置。例如Release LIB、Release DLL等。

我不能做的是编辑所有头文件以添加
__declspec(dllexport) 指令导出,因为库必须是
保持原样。

只需添加带有导出函数列表的模块定义文件 (*.def)。

换句话说,我可以像使用导出库一样使用静态库吗
使用 __declspec(dllexport) 生成?

不,这些库是不同的。当你构建一个 DLL 时,你会得到一个二进制文件和一个 lib 文件。

I need to compile an existing C++ library both as a lib and a dll, and
then use the static and dynamic libraries in different applications. I
use VS2010.

Create configurations for that. For example Release LIB, Release DLL, etc.

What I can't do is to edit all the header files in order to add
__declspec(dllexport) instructions to export, as the library must be
kept as it is.

Simply add module definition file (*.def) with a list of exported functions.

In other words, can I use the static lib as if was the export lib
generated with __declspec(dllexport)?

No, those libs are different. When you build a DLL you get a binary and a lib files.

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