简体   繁体   English

C ++中的动态库

[英]dynamic library in C++

I have a C++ applicatoin which uses dynamically linked libary. 我有一个使用动态链接库的C ++应用程序。 I have placed application and library on target and application is running. 我已将应用程序和库放在目标上,并且应用程序正在运行。 Now i have changed some thing in library and made the library and replaced old library on target with new library. 现在,我已经更改了库中的某些内容,并制作了库,然后将目标上的旧库替换为新库。

My questions is 我的问题是

  1. Does application takes new libarary with out recompliing and relinking? 应用程序是否无需重新编译和重新链接即可获取新的库文件?

Thanks! 谢谢!

Yes, but only if your new library is ABI compatible with the older one. 是的,但前提是您的新库与旧库兼容。

You can find many info about it on the web. 您可以在网上找到许多有关它的信息。 I'd suggest you to read this FAQ about binary compatibility. 我建议您阅读有关二进制兼容性的常见问题解答

Yes, so long as the interface hasn't changed. 是的,只要界面没有变化即可。 That's one advantage of dynamically-linked libraries. 这是动态链接库的优势之一。

Yes. 是。 The library is loaded at run-time by the dynamic linker. 该库在运行时由动态链接器加载。 As long as the ABI is preserved (same compiler and version), your code will use the new code seamlessly without need for recompilation. 只要保留ABI(相同的编译器和版本),您的代码就可以无缝使用新代码,而无需重新编译。

If you are just talking about binary compatibility and whether it is necessary to recompile and relink the application, then you should read the link provided in peoro's answer. 如果您只是在谈论二进制兼容性,以及是否有必要重新编译和重新链接应用程序,那么您应该阅读peoro答案中提供的链接。

However, I am slightly confused by the "application is running" part of your question. 但是,您的问题的“应用程序正在运行”部分使我有些困惑。 If you mean that it is in fact running at the very moment when you replace the library, then it won't use the new version unless it's restarted first or another instance of the application is started (but then the old instance would still use the old version). 如果您是说它实际上在替换库的那一刻就在运行,那么它将不会使用新版本,除非先重新启动它或启动应用程序的另一个实例(但是旧实例仍会使用旧版本)。 Not every OS will allow you to just replace a library that is in use by an application, but there are workarounds. 并非每个操作系统都允许您仅替换应用程序正在使用的库,但是有一些解决方法。 In Windows, you can't overwrite or delete the old library, but you can move or rename it before putting the new version there. 在Windows中,您不能覆盖或删除旧库,但是可以在将新版本放到那里之前对其进行移动或重命名。 Linux will allow you to delete the old version, and if you copy the new version using the install command, it will do it automatically for you. Linux允许您删除旧版本,如果您使用install命令复制新版本,它将自动为您完成。 But the old version won't be deleted physically from the file system until the application finishes, it will just be invisible. 但是,直到应用程序完成后,旧版本才会从文件系统中物理删除,它只是不可见的。

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

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