编译 C++ VS 的静态库和动态 dll 库
我需要将现有的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此创建配置。例如Release LIB、Release DLL等。
只需添加带有导出函数列表的模块定义文件 (*.def)。
不,这些库是不同的。当你构建一个 DLL 时,你会得到一个二进制文件和一个 lib 文件。
Create configurations for that. For example Release LIB, Release DLL, etc.
Simply add module definition file (*.def) with a list of exported functions.
No, those libs are different. When you build a DLL you get a binary and a lib files.