Are standard C library structures compatible between compilers and library versions on MacOS or Linux?

My host application took over, for example. FILE object that comes from the dynamic library. Can I call fclose()this object safely even if my host application and dynamic library are compiled with different versions of clang / gcc?

Background

On Windows (with different versions of VS), this would be illegal, and I must first extract the function fclose()from the runtime library, which is used by the dynamic library, since all runtime environments have their own pools and internal structures for the file or memory objects.

An illustration for a Windows situation would look like this:

library interaction diagram in Windows

Does this restriction apply to Linux and macOS?

+6
source share
3 answers

The problem is not whether your application and dynamic libraries were compiled with different versions of clang and / or gcc. The problem is whether there is ultimately one C base library that manages one kind of FILE * object and has one compatible implementation fclose().

On MacOS and Linux, at least the answer to all these questions is likely to be yes. In my experience, it's hard to get two different, incompatible C libraries in a mix; you have to really work on it.


: , , , . , Unix- C, /lib/libc.{a,so}. , "" , , , , , , . , , , , , , , .

+4

, , . , , , , .

.

(, clang 73 clang 89), (, Apple clang versus GCC), . . , , , . , .

+1

Linux, , (, libc.so.6), . , ldd.

If you linked to a library statically linked in a supporting library, you need to be careful to pass any structures to or from it with the same version of the library. But this is likely to be implemented in practice with libc++and libstdc++than with libc.

So, do not statically link your library to another, and then pass in a data structure that requires client code to reference the same library separately.

+1
source

All Articles