skip to Main Content

I want to compile my c programs on Ubuntu 22.04.3 LTS running on WSL-2. Try as I might, I keep getting the following error:

> myFile1.c:1:10: fatal error: stdio.h: No such file or directory
> 1 | #include <stdio.h>
>       |          ^~~~~~~~~
> compilation terminated.

It seems that the standard gcc header files were never installed in /usr/include

Does anyone have ideas on how I can trouble shoot this? Thanks!

What I tried before:

I initially ran…

$ sudo apt install gcc

then…

$ sudo apt install gcc --fix-missing

then…

$ sudo apt-get update && sudo apt-get upgrade -y

$ sudo apt autoremove -y

$ sudo apt-get install gcc -y

However, none of this fixed the problem. When I run gcc myFile.c -o myProgram.exe && ./myProgram I get the same error as above.

2

Answers


  1. Chosen as BEST ANSWER

    Okay, here is what I did.

    1. I got rid of all my gcc stuff (probably not nessessary):

      sudo apt remove gcc

    2. I made a backup of my /etc/apt/sources.list:

      sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup

    3. Found a mirror site to get my gcc files by going to https://help.ubuntu.com/community/Repositories/CommandLine Followed the link "official mirror list" on that page Found a mirror for the United States (I used Pilot Fiber)

    4. Grabbed the URL from the mirror site https://mirror.pilotfiber.com/ubuntu/

    5. Edited my sources.list to include the mirror site

      sudo nano /etc/apt/sources.list

      then commented out top repository and added the mirror-site repository

      [COMMENTED OUT -->] #deb http://archive.ubuntu.com/ubuntu/ jammy main
      restricted

      [ADDED -->] deb https://mirror.pilotfiber.com/ubuntu/ jammy main

      FYI, jammy is the codename for my Ubuntu distribution (you can find yours via the command line with lsb_release -a)

    6. Updated my apt source list

      sudo apt update

    7. Used apt to install "build-essential" which includes the gcc compiler

      sudo apt install build-essential

    8. Checked for gcc

      gcc -version

      output: gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 ...

    9. Successfully compiled and ran some test programs


  2. You need to install glibc or other libc implementation. I recommend installing the build-essential package.

    sudo apt upgrade
    sudo apt install build-essential
    

    The build-essential package is designed to include software necessary to build Debian packages, which probably isn’t what you need — but includes all the packages necessary to build C code, including gcc and glibc.

    Minimally, you can install the libc6-dev package.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search