S Andrew
S Andrew

Reputation: 7198

How to resolve issue with gcc internal compiler error: Segmentation fault

I have written a "hello world" C code:

#include<stdio.h>
int main()
{
  printf("hello world");
  return 0;
}

When running the below command:

gcc main.c -o main

I am getting below error:

main.c: In function ‘main’:
main.c:8:1: internal compiler error: Segmentation fault
 }
 ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.

Below is the output of lsb_release -a:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.6 LTS
Release:        18.04
Codename:       bionic

gcc version:

gcc (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

How can I resolve this issue?

Edit

I compiled the code with g++:

g++ main.c -o main

and it worked fine with no errors.

Upvotes: 1

Views: 4636

Answers (1)

Andrew Henle
Andrew Henle

Reputation: 1

Given your GCC version of gcc (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0 this is an Ubuntu problem. Ubuntu 18.04 was released 4 1/2 years ago, and the odds of this being a problem with GCC itself are rather slim. As @thebusybee noted in the comments, this is almost certainly something caused by some problem with the compiler installation.

What you need to do is find out what's wrong with your Ubuntu GCC installation. First, make sure you're not doing something that causes the problem. Environment variables such as LD_PRELOAD (or any of the LD_* envvals) can effect GCC. There's also many other envvals that can.

Since you post that you can't upgrade the OS, that implies you're working in an organization with separate system administrator(s) that control the OS installation. So if GCC's failing is not caused by something you're doing this is really the system administrators' problem to solve. If your organization gives them control of the OS installation, that includes everything that they control and you're unable to change, such as the OS-supplied GCC installation here.

What you can do to keep working:

  • First, make sure you're not doing something to cause the problem
  • Install a version of GCC somewhere you are allowed to modify, such as your home directory
    • Modify your PATH and other necessary envvals to used your local GCC copy
  • Use your organization's process(es) to create a trouble ticket to have your system administrator(s) investigate and repair your system. If you're not allowed to modify it, it's their problem.
  • If you have the time, you add something like the -v verbose flag or use GCC's Developer Options such as -freport-bug to try to figure out what's wrong with your system and help your system administrator(s) in solving the real problem here.

Upvotes: 1

Related Questions