If a shared library written in C++ updates (only add some new class member functions), should I recompile the whole program ?
如果用c++编写的共享库更新(只添加一些新的类成员函数),我应该重新编译整个程序吗?
How about I add some public or private data members?
我添加一些公共或私有数据成员如何?
thanks
谢谢
3 个解决方案
#1
1
As long as it is a shared library, linked dynamically with your main program, no you don't, except if you updated the headers shared between your main app and the library.
只要它是一个共享库,与主程序动态链接,不需要,除非更新主应用程序和库之间的头文件。
Object size might have been updated and if you use static allocations on your main program, that could create strange issues (new object size will overflow) :
对象大小可能已经更新,如果您在主程序上使用静态分配,可能会产生奇怪的问题(新对象大小将溢出):
int main(int argc, char * argv[])
{
MyClass list[12];
return 0;
}
Changing object size (by adding members typically) of MyClass on a dynamic library will be a serious problem!
动态库中的MyClass更改对象大小(通常是添加成员)将是一个严重的问题!
#2
1
There are two keywords you should do further reading into: Source compatibility, which means that your program will still compile after updating the library, and binary compatibility, which means that your compiled program will still run without problems after updating the library.
有两个关键字需要进一步阅读:源兼容性,这意味着您的程序在更新库和二进制兼容性之后仍然会编译,这意味着您的编译程序在更新库之后仍然可以运行。
Most major libraries (such as glibc
or libpng
) stay binary-compatible for long version ranges (usually all releases of a major version are binary compatible), and almost never break source compatibility.
大多数主要的库(如glibc或libpng)在长版本范围内保持二进制兼容(通常主要版本的所有版本都是二进制兼容的),而且几乎从不破坏源兼容性。
There are automated tools to test binary and source compatibility (such as this one).
有自动化的工具来测试二进制和源代码的兼容性(比如这个)。
#3
0
There are two answers to this question: No and yes.
这个问题有两个答案:不,是的。
If the library only have a minor update, or if the new functionality is added in a backward-compatible way, then you should not need to do anything. Unless you want to use the new functions of course, then you have to modify your code and recompile it.
如果库只有一个小的更新,或者如果新的功能以向后兼容的方式添加,那么您就不需要做任何事情。除非您想要使用新的函数,否则必须修改代码并重新编译它。
On the other hand, if the library have made some changes that are not backwards compatible, then you might have to at least relink your project. However, the operating system may keep the old versions around if you install such a backwards-incompatible library, so your application may then use the old version and you would not have to do anything.
另一方面,如果库已经做出了一些不向后兼容的更改,那么您可能至少需要将您的项目重新链接起来。但是,如果您安装了这样一个向后兼容的库,操作系统可能会保留旧版本,所以您的应用程序可能会使用旧版本,而您不需要做任何事情。
#1
1
As long as it is a shared library, linked dynamically with your main program, no you don't, except if you updated the headers shared between your main app and the library.
只要它是一个共享库,与主程序动态链接,不需要,除非更新主应用程序和库之间的头文件。
Object size might have been updated and if you use static allocations on your main program, that could create strange issues (new object size will overflow) :
对象大小可能已经更新,如果您在主程序上使用静态分配,可能会产生奇怪的问题(新对象大小将溢出):
int main(int argc, char * argv[])
{
MyClass list[12];
return 0;
}
Changing object size (by adding members typically) of MyClass on a dynamic library will be a serious problem!
动态库中的MyClass更改对象大小(通常是添加成员)将是一个严重的问题!
#2
1
There are two keywords you should do further reading into: Source compatibility, which means that your program will still compile after updating the library, and binary compatibility, which means that your compiled program will still run without problems after updating the library.
有两个关键字需要进一步阅读:源兼容性,这意味着您的程序在更新库和二进制兼容性之后仍然会编译,这意味着您的编译程序在更新库之后仍然可以运行。
Most major libraries (such as glibc
or libpng
) stay binary-compatible for long version ranges (usually all releases of a major version are binary compatible), and almost never break source compatibility.
大多数主要的库(如glibc或libpng)在长版本范围内保持二进制兼容(通常主要版本的所有版本都是二进制兼容的),而且几乎从不破坏源兼容性。
There are automated tools to test binary and source compatibility (such as this one).
有自动化的工具来测试二进制和源代码的兼容性(比如这个)。
#3
0
There are two answers to this question: No and yes.
这个问题有两个答案:不,是的。
If the library only have a minor update, or if the new functionality is added in a backward-compatible way, then you should not need to do anything. Unless you want to use the new functions of course, then you have to modify your code and recompile it.
如果库只有一个小的更新,或者如果新的功能以向后兼容的方式添加,那么您就不需要做任何事情。除非您想要使用新的函数,否则必须修改代码并重新编译它。
On the other hand, if the library have made some changes that are not backwards compatible, then you might have to at least relink your project. However, the operating system may keep the old versions around if you install such a backwards-incompatible library, so your application may then use the old version and you would not have to do anything.
另一方面,如果库已经做出了一些不向后兼容的更改,那么您可能至少需要将您的项目重新链接起来。但是,如果您安装了这样一个向后兼容的库,操作系统可能会保留旧版本,所以您的应用程序可能会使用旧版本,而您不需要做任何事情。