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
Okay, here is what I did.
I got rid of all my gcc stuff (probably not nessessary):
sudo apt remove gcc
I made a backup of my /etc/apt/sources.list:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
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)
Grabbed the URL from the mirror site https://mirror.pilotfiber.com/ubuntu/
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)
Updated my apt source list
sudo apt update
Used apt to install "build-essential" which includes the gcc compiler
sudo apt install build-essential
Checked for gcc
gcc -version
output: gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 ...
Successfully compiled and ran some test programs
You need to install
glibc
or other libc implementation. I recommend installing thebuild-essential
package.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.