Using a C library from a non-C program: is it necessary to explicitely initialize the “under-the-hood” C library?

StackOverflow https://stackoverflow.com/questions/10929870

  •  13-06-2021
  •  | 
  •  

Question

I know that when you compile and link a C program, you link it with

  1. C library
  2. C runtime startup code

I wonder if I write a program (in a new language, or just C without linking to this code) and link it directly to a C code shared library (say zlib or gsl or fftw or something) and omitting the C library and C startup code (assuming my program will load the external lib itself using its magic), will this "just work"?

I know there is some initialization code in the CRT startup, so I wonder how I can call the required functions without having my application itself depend on a C library: so loading the external C library will at that point call the necessary initialization code (if any, this is the question), and otherwise just load the OS libraries/interfaces.

The reason I ask is that I want to write a language with a Standard library that hooks into the OS API directly, unlike most C++ implementations, that are built on top of the C library.

Was it helpful?

Solution

Take a look here https://blogs.oracle.com/ksplice/entry/hello_from_a_libc_free
So you can startup your program without depend to any library included libc, then libraries can be load and use as needed later.

OTHER TIPS

I have used C shared libraries from a number of other languages. Whether you must explicitly initialize the shared library depends on the library. Normally, it will be implicitly initialized on load, but some libraries require extra initialization. Read the documentation.

And the code of my program (C or other language) must of course be initialized too, but that is what the compiler/linker usually take care of, by linking to the startup code by default.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top