Gcc фатальная ошибка

CodeWithHarry Logo

CodeWithHarry

Copyright © 2022 CodeWithHarry.com

I’m trying to compile a program in C on OS X 10.9 with GCC 4.9 (experimental). For some reason, I’m getting the following error at compile time:

gcc: fatal error: stdio.h: No such file or directory

I then tried a simple Hello World program:

#include <stdio.h>

int main(int argc, const char *argv[])
{
    printf("Hello, world!");
    return 0;
}

Again, upon running gcc -o ~/hello ~/hello.c, I got the same error. I’m using an experimental version of gcc, but it seems implausible that there would be a release which generated errors upon importing stdio. What could be causing this issue, and how can it be fixed?

asked Oct 25, 2013 at 3:48

Jules's user avatar

JulesJules

14.2k13 gold badges56 silver badges101 bronze badges

13

macOS

I had this problem too (encountered through Macports compilers). Previous versions of Xcode would let you install command line tools through xcode/Preferences, but xcode5 doesn’t give a command line tools option in the GUI, that so I assumed it was automatically included now. Try running this command:

xcode-select --install

If you see an error message that developer tools are already installed (and still header files can’t be found), wipe out any existing one to do a fresh installation:

sudo rm -rf /Library/Developer/CommandLineTools

Ubuntu

(as per this answer)

sudo apt-get install libc6-dev

Alpine Linux

(as per this comment)

apk add libc-dev

Jongwook Choi's user avatar

answered Nov 22, 2013 at 16:55

amos's user avatar

amosamos

5,0224 gold badges34 silver badges42 bronze badges

6

Mac OS Mojave

The accepted answer no longer works. When running the command xcode-select --install it tells you to use «Software Update» to install updates.

In this link is the updated method:

Open a Terminal and then:

cd /Library/Developer/CommandLineTools/Packages/
open macOS_SDK_headers_for_macOS_10.14.pkg

This will open an installation Wizard.

Update 12/2019

After updating to Mojave 10.15.1 it seems that using xcode-select --install works as intended.

answered Feb 3, 2019 at 4:10

Samshel's user avatar

SamshelSamshel

9288 silver badges12 bronze badges

4

On Ubuntu:

sudo apt-get install libc6-dev

specially ruby developers that have problem installing gem install json -v '1.8.2' on their VMs

vvvvv's user avatar

vvvvv

23.9k19 gold badges48 silver badges75 bronze badges

answered Mar 26, 2015 at 17:23

equivalent8's user avatar

equivalent8equivalent8

13.6k8 gold badges81 silver badges109 bronze badges

3

I know my case is rare, but I’ll still add it here for someone who troubleshoots it later.
I had a Linux Kernel module target in my Makefile and I tried to compile my user space program together with the kernel module that doesn’t have stdio.
Making it a separate target solved the problem.

answered May 4, 2020 at 19:57

Soid's user avatar

SoidSoid

2,5291 gold badge30 silver badges42 bronze badges

I had the same problem. I installed «XCode: development tools» from the app store and it fixed the problem for me.

I think this link will help:
https://itunes.apple.com/us/app/xcode/id497799835?mt=12&ls=1

Credit to Yann Ramin for his advice. I think there is a better solution with links, but this was easy and fast.

Good luck!

answered Oct 25, 2013 at 20:43

nevieandphil's user avatar

1

When i tried to run hello program of C on the terminal the following error comes:

$ gcc hello.c -o hello
gcc: error: hello.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.

Evandro Silva's user avatar

asked Jan 19, 2015 at 17:28

Rahul Dev's user avatar

2

The clue is in the No such file or directory; it can’t find the right file. Either…

  • You’re not in the same directory as your hello.c file. cd to the right directory, or use provide gcc with the path to the file:

    gcc /home/oli/Desktop/hello.c -o hello
    

    Note the same applies to the -o output path. If you leave it as hello it will try to write to the current working directory (/home/$USER/ by default). Either change directory or provide a full path.

  • Or you’ve called it HellO.C (Ubuntu’s filesystems are case sensitive).

  • hello.c never existed. Perhaps it was just a figment of our collective imaginations; perhaps you forgot to save it; perhaps it’s called something else completely.

This is the second time you’ve posted about path issues. It’s something you’ll learn but yeah, commands don’t just work globally and not all files live in the same directory. You have to specify where stuff is.

Community's user avatar

answered Jan 19, 2015 at 17:33

Oli's user avatar

OliOli

288k117 gold badges677 silver badges832 bronze badges

You should first check the path properly, Whether your c file does exist in this folder or not. For that, you can use ls command to list out all the files in this particular folder.

And for seeing the path for the folder, You can use pwd.

Hope this will help you. Because to compile the c file you have entered the right command only.

answered Apr 1, 2020 at 16:35

Pooja Khatri's user avatar

I had the same problem while using CMakeLists to compile some C programs. I used # in the following to comment the rest of flags:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-pragmas -Wno-format -Wno-unused-label -Wno-unused-function # -Wno-int-to-void-pointer-cast -Wno-self-assign")

but it turns out that I can’t comment it like that so I just removed the rest (# -Wno-int-to-void-pointer-cast -Wno-self-assign) and it compiled.

answered Jan 13, 2021 at 9:09

Keivan's user avatar

KeivanKeivan

1012 bronze badges

My situation. uname -a gives Linux computer2 4.4.0-62-generic #83~14.04.1-Ubuntu SMP Wed Jan 18 18:10:30 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

I am trying to install HDF5 1.8.18 with GNU make 3.81 invoking gcc 6.3.0. I have successfully installed this gcc 6.3.0 alongside the version 4.8.4 that is shipped with the Ubuntu distribution.

My gcc 6.3.0 lives in /opt/gcc/6_3_0/. I use the following script to configure and pass on the commands, libraries and headers in non-standard directories:

export FC='/opt/gcc/6_3_0/bin/gfortran-6.3.0'   # probably unnecessary
export CC='/opt/gcc/6_3_0/bin/gcc-6.3.0'  
export CXX='/opt/gcc/6_3_0/bin/g++-6.3.0' 
export CPP='/opt/gcc/6_3_0/bin/cpp-6.3.0'
export LDFLAGS='-L/opt/gcc/6_3_0/lib -L/opt/gcc/6_3_0/lib64' 
export CPPFLAGS='-I/opt/gcc/6_3_0/include -I/opt/gcc/6_3_0/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include'

./configure 
--prefix=${insdir} 
--with-zlib=${zlibdir}/include,${zlibdir}/lib 
--enable-fortran 
--enable-cxx

where ${insdir} is an installation directory, ${zlibdir} is where zlib lives and the other switches are standards as per the installation guidelines

The configure step goes well. The make step fails with the error:

make[2]: Entering directory `<the source directory>/hdf5-1.8.18/c++/src'
CXX      H5Exception.lo
H5Exception.cpp:16:18: fatal error: string: No such file or directory
#include <string>
                ^
compilation terminated

If I understand it correctly, some header file is missing, and of a basic nature.

  • Where should I get it from?
  • Is there any flaw in the names and values of the environment variables?

StackExchange contains a host of posts on this error, but they seem to be mostly related to coding exercises. My aim is not to edit codes, rather to compile source codes successfully with my vanilla gcc 6.3.0.

Updated question

In the light of the helpful comments and Thomas Dickey’s answer below, it appears that a promising avenue is to install matching versions of libstdc++ and gcc. I have searched around in the GCC website and it appears that one can configure gcc with the following switch

—enable-version-specific-runtime-libs

Specify that runtime libraries should be installed in the compiler specific subdirectory (libdir/gcc) rather than the usual places. In addition, libstdc++’s include files will be installed into libdir unless you overruled it by using —with-gxx-include-dir=dirname. Using this option is particularly useful if you intend to use several versions of GCC in parallel. This is currently supported by ‘libgfortran’, ‘libstdc++’, and ‘libobjc’.

  • Is this pointing in the right direction?
  • Where would I be supposed to find the libstdc++’s include files that are distributed alongside the source of gcc, if this is switch is not used?

@Haghrah

I am trying to compile and run a simple hello world c++ code. g++ says no input files:

g++: fatal error: no input files
compilation terminated.

It seems that the g++ is not running in the same directory which c++ file is placed or maybe file path is not correct in compilation command. How to solve the problem?

@Godsgrav3

hi @Haghrah Do you still have this issue? If so check if g++ is in your PATH variables by opening CMD and entering the following: «gcc —version» and «g++ —version». if you do not see information check you my issue #132

@LiamInfoSec

I have the same problem when I run «g++ —version»;

g++ (MinGW.org GCC-8.2.0-3) 8.2.0
Copyright (C) 2018 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.

@michael-rishi

in my terminal i am trying to run a welcome.cpp file that’s code is

# include <iostream>
using namespace std;
int main()
{
cout >> «Hello What’s your name «
char name = «»
cin << name << endl
char msg = «Hello » + name + «. Nice to meet you!»
cout >> msg >> endl
cout >> «» >> endl
}

and when I type «g++ -o welcome.cpp» then enter this is what comes up

Screenshot from 2019-06-08 12-18-01

hamraniali, rebroad, alonsogalcantara, sarthakbhatkar1, khan-rehan, weolix, souvenger, Siddhant-K-code, 01-Menjivar, Harshdeep-Yadav, and jayeshmon reacted with thumbs up emoji
jim4067, damaputraa, sarthakbhatkar1, khan-rehan, weolix, arjun-gn, ratan10, vikash232, bai62, SundiataB, and 8 more reacted with eyes emoji

@Godsgrav3

@rishiamalhotra

for one, your code will not compile, you have multiple fatal errors in your code.
#include <iostream> is not used, is necessary for cout.
cout doesn’t use >>, but <<
you miss ; in your code, c and c++ do need this to work.

addressing the fatal error.
You can compile and run it from the UNIX prompt as follows :
% g++ welcome.cpp
This creates an executable called «a.out». You can run it by typing
% ./a.out
Since no executable name was specified to g++, a.out is chosen by default. Use the «-o» option to change the name :
% g++ -o welcome welcome.cpp
creates an executable called «welcome».

@hg0428

@Kusumadhanush22

@teslayder

me the same and when I run code again it announce Code is already running!

@weolix

in my terminal i am trying to run a welcome.cpp file that’s code is

include

using namespace std;
int main()
{
cout >> «Hello What’s your name «
char name = «»
cin << name << endl
char msg = «Hello » + name + «. Nice to meet you!»
cout >> msg >> endl
cout >> «» >> endl
}

and when I type «g++ -o welcome.cpp» then enter this is what comes up

Screenshot from 2019-06-08 12-18-01

指令用错了,应该是

g++ welcome.cpp -o welcome

@weolix

I got the same mistake. That’s funny.

@adarsh-dhakad

@mar-tnk

Just go with «g++ -o welcome welcome.cpp»

@nishihere19

@rishiamalhotra

for one, your code will not compile, you have multiple fatal errors in your code.
#include <iostream> is not used, is necessary for cout.
cout doesn’t use >>, but <<
you miss ; in your code, c and c++ do need this to work.

addressing the fatal error.
You can compile and run it from the UNIX prompt as follows :
% g++ welcome.cpp
This creates an executable called «a.out». You can run it by typing
% ./a.out
Since no executable name was specified to g++, a.out is chosen by default. Use the «-o» option to change the name :
% g++ -o welcome welcome.cpp
creates an executable called «welcome».

Thanks a lot. My issue is solved now. The file is working for me now.

@mrxcrx

Don’t use name file with space, u must be used underline

@marco2942

@Abhinow-katore

Don’t use name file with space, u must be used underline

Thank you 👍My issue is solved now

@sid25j

I have the same issue

`#include
int main()
{
std::cout << «Hi» <<std::endl;
return 0;

}`

Screenshot from 2021-08-12 20-54-13
.

@weolix

«g++ -o target source.cpp»

@Colebie

I had the same problem, I was trying to compile had the same error, test to see if you have installed:-
~$ gcc —version
~$ g++ —version
~$ clang —version
~$ gdb —version
and set the path

@mohamedabdallah1996

make sure that the path of the file you are running not have any white spaces

@hoang1904

i have a same issue too
#include<stdio.h>
int soChuSo(int n){
if(n==0)
return 0;
return 1+soChuSo(n/10);
}

int tongChuSo(int n){
if(n>0)
return n%10+tongChuSo(n/10);
return 0;
}

int main(){
int n;
printf(«Nhap so nguyen n: «);
scanf(«%d»,&n);
printf(«So n co %d chu son»,soChuSo(n));
printf(«Tong cac chu so cua n la: %dn»,tongChuSo(n));
return 0;
}
image

@Rakib221

I have this issue too.
I have tried this command: g++ -std=c++11 -Wall -Wextra -pedantic-errors -o 4A.cpp
MY CODE:
#include
using namespace std;
void evenDivisible(int weight);
int main()
{
int watermelonWeight;
cout << «Enter water melon weight: » ;
cin >> watermelonWeight;
if (watermelonWeight >= 1 && watermelonWeight <= 100)
evenDivisible(watermelonWeight);
else
cout << «Please enter number in this range 1<=n>=100» << endl;
}

void evenDivisible(int weight)
{
if (weight > 2 && weight % 2 == 0)
cout << «Yes» << endl;
else
cout << «No» << endl;
}

@Shndigan

I think i solve the problem guys, check out if there is another MinGw64 folder installed in ur pc or not.
if there is then just delete it bcs system cant read 2 folder’s g++.exe file :) i hope that i solved your problems

@Jerry-autumn

The first aspect: First, the file contains are not written(#include ;#include ), and secondly «cout << «No» << endl;»should be written like «cout << «» << endl;»; if «string msg = «Hello » + name + «. Nice to meet you!»; 如果使用这个需要进行运算符重载;» operation requires operator overloading
The second aspect: the reason for the error may be the environment, check your gcc environment境

Понравилась статья? Поделить с друзьями:
  • Galileos viewer ошибка 0xc0150002
  • Gcb trip ошибка генератора
  • Galaxy64 dll ошибка
  • Gcb 24 quantum fi коды ошибок
  • Gardena r50li ошибки