简体   繁体   中英

Can I use one Linux .so for all Linux compilers?

We need to integrate a closed-source C library into our project. The other party can compile the library in any mode we need, but we support a lot of different Windows and Linux compilers.

I know a DLL will be compatible with all major Windows compilers, so we could only use one library for Windows. But I'm not familiar with Linux dynamic libraries (.so). Are these compatible across all Linux environments in a similar way?

Thanks

You may have some issues wrt the version of the GNU libc against which that shared library libotherparty.so has been linked (and compiled).

You certainly need to know the version of the libc, and you might require that party to ship several variants of the binary library.

I would strongly suggest to read Drepper's paper: How To Write Shared Libraries . See also this question and Levine's linker & loader book.

If it is C code, the compiler does not matter much. What matters more is the ABI . Learn also about symbol versioning .

Be prepared to have some trouble.

You'll learn by experience that free software is preferable.

Library versions should be specified for shared objects if the function interfaces are expected to change (C++ public/protected class definitions), more or fewer functions are included in the library, the function prototype changes (return data type (int, const int, ...) or argument list changes) or data type changes (object definitions: class data members, inheritance, virtual functions, ...).

The library version can be specified when the shared object library is created. If the library is expected to be updated, then a library version should be specified. This is especially important for shared object libraries which are dynamically linked. This also avoids the Microsoft "DLL hell" problem of conflicting libraries where a system upgrade which changes a standard library breaks an older application expecting an older version of the the shared object function.

Versioning occurs with the GNU C/C++ libraries as well. This often make binaries compiled with one version of the GNU tools incompatible with binaries compiled with other versions unless those versions also reside on the system. Multiple versions of the same library can reside on the same system due to versioning. The version of the library is included in the symbol name so the linker knows which version to link with.

One can look at the symbol version used: nm csub1.o

00000000 T ctest1

No version is specified in object code by default.

Look ld and object file layout

There is one GNU C/C++ compiler flag that explicitly deals with symbol versioning. Specify the version script to use at compile time with the flag: --version-script=your-version-script-file

Note: This is only useful when creating shared libraries. It is assumed that the programmer knows which libraries to link with when static linking. Runtime linking allows opportunity for library incompatibility.

Also look here regarding ABI compatibility

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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