1

Is it possible to compile C "Hello world" program to have final executable entirely static?

#include <stdio.h>

int main() {
    printf("hello world!\n");

    return 0;
}

I've tried the following:

clang -static main.c

But it gives:

ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've seen staticly linked libc? but I want to get additional information on this topic.

P.S. I am asking this for education purposes rather than for real practice.

Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129

0 Answers0