简体   繁体   English

如何解决 gcc 内部编译器错误的问题:分段错误

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

I have written a hello world c code:我写了一个hello world c代码:

#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 :下面是lsb_release -a的 output :

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

gcc version: gcc 版本:

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.

Can anyone please help me resolve this issue?谁能帮我解决这个问题? Thanks谢谢

EDIT:编辑:

I compiled the code with g++ :我用g++编译了代码:

g++ main.c -o main

and it worked fine with no errors.它运行良好,没有错误。 I am not sure what I can do to resolve issue with gcc.?我不确定如何解决 gcc 的问题。?

Given your GCC version of gcc (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0 this is an Ubuntu problem.鉴于您的 GCC 版本的gcc (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0这是一个 Z3D945423F8E9496C429FZB5D8 问题。 Ubuntu 18.04 was released 4 1/2 years ago , and the odds of this being a problem with GCC itself are rather slim. Ubuntu 18.04 于 4 1/2 年前发布,而 GCC 本身存在问题的可能性很小。 As @thebusybee noted in the comments, this is almost certainly something caused by some problem with the compiler installation.正如@thebusybee 在评论中指出的那样,这几乎肯定是由编译器安装问题引起的。

What you need to do is find out what's wrong with your Ubuntu GCC installation.您需要做的是找出您的 Ubuntu GCC 安装有什么问题。 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.诸如LD_PRELOAD (或任何LD_* envvals)之类的环境变量会影响 GCC。 There's also many other envvals that can . 还有许多其他 envvals 可以

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.因此,如果 GCC 的失败不是由您正在做的事情引起的,那么这确实是系统管理员要解决的问题。 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.如果您的组织授予他们对操作系统安装的控制权,包括他们控制且您无法更改的所有内容,例如此处的操作系统提供的 GCC 安装。

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允许修改的地方安装 GCC 版本,例如您的主目录
    • Modify your PATH and other necessary envvals to used your local GCC copy修改您的PATH和其他必要的环境以使用您的本地 GCC 副本
  • 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.如果您有时间,您可以添加类似-v详细标志之类的内容或使用GCC 的开发人员选项(例如-freport-bug )来尝试找出您的系统出了什么问题并帮助您的系统管理员在这里解决真正的问题.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM