Search code examples
cstartuplibccrt

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


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.


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.