4

Why am I getting this message? The compiler is clang. Here is a simple program where it occurs for examples sake:

#include<stdio.h>

int fib(int);
int main()
{
    int i;
    scanf("%d",&i);
    printf("The fibonacci number that is %i'th in the sequence is %i \n", i, fib(i));
return 0;
}

int fib(int n)
{
    if (n==1 || n==0) return 1;
    else return fib(n-1)+fib(n-2);
}
jones
  • 361
  • 1
  • 4
  • 13

2 Answers2

14

Assuming C

<stdio.h> is one of the standard C headers. Your compiler complains that it can not find this header. This means that your standard library is broken.

Consider reinstalling your compiler.

Assuming C++

<stdio.h> is the C standard header, with C++ we use <cstdio> instead. Though <stdio.h> is still required to exist in C++, so this probably isn't the problem.


Apart from these assumptions, it seems most likely (by your coding style and tags) that you are using C. Try this as some example code. This is guaranteed (by me) to compile on a working C compiler, if it doesn't then your compiler is horribly broken and you must install another one/reinstall:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) {
    printf("Hello World!\n");
    return EXIT_SUCCESS;
}
orlp
  • 112,504
  • 36
  • 218
  • 315
  • 2
    That's the answer I always wanted to give, but was afraid to make – Gunther Piez May 05 '11 at 13:15
  • 2
    However, stdio.h is still part of Standard C++. –  May 05 '11 at 13:19
  • I just reinstalled clang as root in Ubuntu 'sudo apt-get install clang' etc It is compiling now. Thanks for you time. So sorry to bother with such a simple issue, I was hoping to get insight into why this might have occurred. – jones May 05 '11 at 13:22
  • unapersson: __It is not.__ Often on systems where you compile C++ `stdio.h` can be found in the include dir, heck, often this `stdio.h` file includes support for C++, but it is by no means part of Standard C++. – orlp May 05 '11 at 13:23
  • 2
    @nightcracker Its presence is normative (i.e. required) for the current C++ standard, but may be removed in later ones (actually it won't be). See the C++ Standard Annex D. –  May 05 '11 at 13:49
  • The C++ advice in this answer is wrong, especially the advice to use `iostream` which is usually considered one of the worst mistakes of C++ (especially its stateful formatting interface which is nearly impossible to use in code that might be multi-threaded). – R.. GitHub STOP HELPING ICE May 05 '11 at 18:40
  • @R. What else is wrong, except the use of `iostream` in my answer (you said especially). Please note that I'm still learning C++ and most of my opinions come straight from learning material, I haven't had my own experiences apart from very basic ones. – orlp May 05 '11 at 18:44
  • `` **is** part of the C++ standard, as of the current published version. – R.. GitHub STOP HELPING ICE May 05 '11 at 18:49
  • 1
    On Slackware 14.2 after updates, it was not sufficient to reinstall `gcc` only, for compile this example. One additional step needed: `slackpkg install glibc*`. – jpka Oct 31 '17 at 10:35
  • On Mint 19 I had to use `sudo apt-get update` and then `sudo apt-get install build-essential` on a fresh installation. None of the above worked for me. – ESL Nov 02 '20 at 04:06
0

I got a runtime error similar to this while using C++ in Visual Studio 2017. The solution in my case was to simply clean and rebuild the solution

public wireless
  • 767
  • 8
  • 20