简体   繁体   English

供应商如何提供C ++库支持多个编译器?

[英]How does a vendor supplied C++ library support multiple compilers?

I make use of a vendor supplied library in a C++ program . 我在C++ program使用供应商提供的库。 All the vendor supplies is a .lib, .dll and the header files. 所有供应商耗材都是.lib, .dll and the header files.

This library was first used in MSVC++ 6 and now in MSVC 2010. 该库最初用于MSVC++ 6 ,现在用于MSVC 2010.

It appears they support mingw, qt, etc. I have had no problems with using it in either debug or release mode. 它似乎支持mingw,qt等。我在调试或发布模式下使用它没有任何问题。

I have recently added another dependency to the project, yaml-cpp , an open-source project that provides no binaries. 我最近为项目yaml-cpp添加了另一个依赖项, yaml-cpp是一个不提供二进制文件的开源项目。 I am able to build yaml-cpp using cmake and MSVC 2010 as a static library and can link it to my project successfully. 我能够使用cmake和MSVC 2010作为静态库构建yaml-cpp,并且可以成功地将它链接到我的项目。

In order to do this I must link to the debug and release versions of the .lib respectively as I have run in to weird Microsoft CRT/linker issues I am just learning about. 为了做到这一点, 我必须分别链接到 .lib 的调试发布版本,因为我遇到了奇怪的Microsoft CRT /链接器问题我正在学习。

I am curious, how does the vendor of my first library (libXl if you are curious) provide a .lib and .dll that works on a range of compilers without worrying about the CRT version ? 我很好奇, 我的第一个库的供应商(libXl,如果你很好奇)如何提供一个.lib and .dll ,它可以在一系列编译器上运行而不用担心CRT版本

How do you write code that allows this or is it the linking process? 你如何编写允许这个或者是链接过程的代码? yaml-cpp is a cross platform library , is it possible for me to compile it in a similar way that would allow me to use a single .lib within my project? yaml-cpp是一个跨平台库 ,我可以用类似的方式编译它,这样我就可以在我的项目中使用单个.lib吗?

I am not sure what resources to look for to learn more about it. 我不确定需要哪些资源来了解它。 How do people learn about this kind of stuff? 人们如何了解这类东西? Thanks! 谢谢!

The reason that a .lib and dll can work with a variety of compilers is down to ensuring that there are no compiler-specific dependencies in your code. .lib和dll可以与各种编译器一起工作的原因在于确保代码中没有特定于编译器的依赖项。 .lib and .dll are not recompiled so once they are made they should be stand-alone if so coded, and their functionality can be accessed from anywhere with the ability to use a .dll or a .lib. .lib和.dll不会被重新编译,所以一旦它们被创建,它们应该是独立的,如果这样编码的话,它们的功能可以从任何地方访问,并且能够使用.dll或.lib。

There is some discussion on the pros and cons of dll and lib here which you may find interesting. 上有优点和dll和lib的利弊进行一些讨论在这里 ,你可能会觉得有趣。

Let me know if you need more info and I will do my best to oblige. 如果您需要更多信息,请告诉我,我会尽我所能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM