facha
facha

Reputation: 12522

How to make a fix in one of the shared libraries (.so) in the project on linux?

I want to make a quick fix to one of the project's .so libraries. Is it safe to just recompile the .so and replace the original? Or I have to rebuild and reinstall the whole project? Or it depends?

Upvotes: 5

Views: 1699

Answers (5)

Alex B
Alex B

Reputation: 84832

It depends. Shared library needs to be binary-compatible with your executable.

For example,

  1. if you changed the behaviour of one of library's internal functions, you probably don't need to recompile.
  2. If you changed the size of a struct (e.g. by adding a member) that's known by the application, you will need to recompile, otherwise the library and the application will think the struct is smaller than it is, and will crash when the library tries to read an extra uninitialized member that the application didn't write to.
  3. If you change the type or the position of arguments of any functions visible from the applications, you do need to recompile, because the library will try to read more arguments off the stack than the application has put on it (this is the case with C, in C++ argument types are the part of function signature, so the app will refuse run, rather than crashing).

The rule of thumb (for production releases) is that, if you are not consciously aware that you are maintaining binary compatibility, or not sure what binary compatibility is, you should recompile.

Upvotes: 4

Gregory Pakosz
Gregory Pakosz

Reputation: 70204

If you don't change your library binary interface, it's ok to recompile and redeploy only the shared library.

Good references:

Upvotes: 1

murrekatt
murrekatt

Reputation: 6129

It depends yes.

However, I assume you have the exact same source and compiler that built the other stuff and now if you only change in a .cpp file something, it is fine.

Other things e.g. changing an interface (between the shared lib and the rest of the system) in a header file is not fine.

Upvotes: 1

nos
nos

Reputation: 229128

If you have not changed the ABI of the shared library, you can just rebuild and replace the library.

Upvotes: 1

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81694

That's certainly the intent of using dynamic libraries: if something in the library needs updating, then you just update the library, and programs that use it don't need to be changed. If the signature of the function you're changing doesn't change, and it accomplishes the same thing, then this will in general be fine.

There are of course always edge cases where a program depends on some undocumented side-effect of a function, and then changing that function's implementation might change the side-effect and break the program; but c'est la vie.

Upvotes: 1

Related Questions