Home > Enterprise >  segmentation fault without standard libraries
segmentation fault without standard libraries

Time:05-10

I am trying to write a simple C program without including standard libraries and trying to compile and run with gcc. but I was getting segmentation fault( core dumped )

main.c:

int main(){}

commands executed:

  1. gcc main.c -c -ffreestanding
  2. gcc main.o -e main -nostdlib
  3. ./a.out

output:

Segmentation fault (core dumped)

any help would be greatly appreciated.

CodePudding user response:

Besides the problem mentioned in the comments, there is also a problem during the link time. If you run it with the flag -nostdlib, it will ignore the symbol symbol _start, which is part of a default library, crt0.o.

  • Related