0

I need to use the C standard to compile with my POSIX implementation. I downloaded the precompiled lib of gcc-11.2, but after unzipping, I am facing libgcc.a and libc.a libraries.

I tried to compile with libc.a, but <stddef.h> is missing. I compiled with both libraries, and it solved the inclusion issue. But a new issue has arisen: the function clock_gettime() isn't being referenced. This function is defined by POSIX (Real Time) as an extension of time.h. I need this file and function for my implementation. I checked with dumpobj on libc.a and libgcc.a, but the function is not present. So, it seems that libc.a has been compiled without the function. A solution can be to compile the GCC sources with the -D_POSIX_TIMERS flag (clock_gettime is defined if _POSIX_TIMERS exists) ?

I don't understand why there are libgcc.a and libc.a instead of one library, what is the difference between these libraries ? And is it possible to use a POSIX function defined in the GCC library without including all the other POSIX features to prevent conflicts with my POSIX implementation ?

6
  • 1
    Any reason you're not installing gcc from your OS's package repository via yum/dpk/apt? Commented Jun 12, 2024 at 13:57
  • 3
    Per the documentation, libgcc is a low-level runtime library, that is used by gcc internals "automatically". While libc is the implementation of C library, that is library functions callable by the "user". Commented Jun 12, 2024 at 14:23
  • Generally, you can't/shouldn't use [purely] the .a version of libc. On linux [at least], you want the shared .so as well. Particularly for clock_gettime because (for optimal performance) it's in the VDSO (code injected into the user program by the kernel). See my answer: __rdtsc/__rdtscp for ARM Mac M1/M2? Commented Jun 12, 2024 at 14:33
  • As a side note, you can't conform to the C standard and POSIX at the same time, pick one, say bye-bye to the other. Commented Jun 12, 2024 at 14:44
  • 1
    @Eoa It is not. For example it is a requirement for a conforming C implementation not to implement something that affects the behavior of a "strictly conforming program", such as adding identifiers that may also be used by the application. In plain English, the C standard libraries are not allowed to contain non-standard trash. Whereas POSIX requires that the standard libraries are filled up with with non-standard trash. Commented Jun 13, 2024 at 13:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.