stdio.h file not found when compiling c program - c

#include <stdio.h>
int main(void)
{
printf ("Programming is fun");
return 0;
}
When I use the cc command in terminal to compile the above program it returns
fatal error: 'stdio.h' file not found`
I compiled this exact code on ubuntu where it created an a.out-file, which sadly did not run either. While I'm not sure why either happens at least no error was produced on ubuntu.

For recent macOS, people would miss C headers after system update.
cd /Library/Developer/CommandLineTools/Packages
open macOS_SDK_headers_for_macOS_xx.pgk
I guess this is another Apple's bug.

You don't specify the platform you're on...
If stdio.h is not found, it usually mean you don't have the necessary header files on your system (usually in /usr/include/).
Your compiler might be working fine, but it looks like the C-Library headers are not installed.
Depending on your platform, you'll have to install them.
It's a bit weird that you have a working compiler without C library headers.
You may want to reinstall your compiler, or search for a package which contains the headers for the C library.
If you're on OS X, (re)install Xcode as well as the command line tools.
If you're on Linux, use your package manager to install the development package for C (e.g. libc6-dev on Debian).

Before you go reinstalling your compiler you might want to check your include paths. As you don't specify your platform I can only provide general information but this is similar on many platforms.
Using cc you need to set them in the environment. Try typing 'env' to see your current settings. There needs to be a line that sets a variable 'include' with the full path to the location of your studio.h.
You can also set the include path in the make file or, if using an IDE, in the project settings.

There is something wrong with how your compiler is configured.

Related

How do install C header files in Mac OSX Sierra?

I have missing header files like malloc.h and conio.h in my MAC.. how do I install it?
gcc linkedlistmenu.c
linkedlistmenu.c:2:19: fatal error: malloc.h: No such file or directory
First off, malloc.h is deprecated (and not available on your system). Instead, you should be using stdlib.h. Furthermore, conio.h is an implementation specific header - and in this case, it is Windows and MS-DOS specific. It is not available on MacOS. Both of these are non-standard headers, and therefore are not preferred due to issues with portability. ncurses (which should already be available on MacOS) provides similar functionality to conio.h; see if that has what you're looking for.
However, your best shot if you really need these header files is to install a virtualization program such as VirtualBox, install Windows, and work from there.

Haskell: Missing C library on Arch Linux works on Ubuntu

I recently switched my PC at work from Ubuntu to Arch Linux.
And I am now getting the following error (I am using stack to build my project):
setup-Simple-Cabal-1.22.4.0-ghc-7.10.2: Missing dependency on a
foreign
library:
* Missing C library: HSrts-ghc7.10.2
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
As far as I understand it, the difference in Linux Distribution should not cause any issue.
Things I have tried:
-add the path where the library is with --extra-lib-dirs
-make sure that the version of stack/ghc are the same acrose both systems
-tried unsucesfully to find a relevant difference between the 2 systems
(gcc version was different but didn't change anything)
I have a docker container based on ubutu where it builds without an issue.
The only thing I can think of is that this library gets handled differently from some random C-library since it contains the Haskell-Runtime. But I have no idea what this difference would be. Or how a differnent handling would cause an issue on my Arch System.
Here my .cabal file (the folder also contains the whole project):
https://github.com/opencog/atomspace/blob/master/tests/haskell/libExecutionOutputTest/opencoglib.cabal
Okay i figured out a workaround, instead of specifiyc the library in the .cabal file:
...
extra-libraries: HSrts-ghc7.10.2
...
you add it to your stack.yaml file:
...
ghc-options:
package-name: -lHSrts-ghc7.10.2
...
If you also have a exectuable defined in your .cabal file this will break the executable, since the library is not only included in the library. And including the runtime library in an executable results in an instant segementation fault.

Setting up avr compiler in code:blocks, not finding #include files

I've installed the avr-gcc compiler and successfully convinced it to compile some test code through the terminal, so I thought I'd have a go at setting it up in code:blocks to make it a little easier to handle.
It seems to have detected it ok and I have it selected in compiler settings, but for some reason it can't find the avr standard libraries when I try to include them (like #include </avr/io.h>). The same code was fine when compiling using the CLI tool.
I tried manually inserting the file path into the include command (#include </usr/lib/avr/include/avr/io.h>) which solved the problem, it was able to find it then, but then it encountered an error in io.h where that file tried to include another .h file and again it couldn't be found.
Short of going through every standard library and manually rewriting every include command, is there a setting somewhere to have the compiler automatically search those directories? I tried giving it the address in
Settings/Compiler/Search Directories/Compiler
Settings/Compiler/Search Directories/Linker
Settings/Compiler/Search Directories/Resource Compiler
Settings/Compiler/Toolchain Executables/Additional Paths
but no joy. Anyone out there know of some field or tickbox I should have filled out?

Strange disconnect between Eclipse CDT, included system headers, and the underlying C build

I'm having a strange problem with include files and an apparent disconnect between Eclipse's build process and its error reporting. I'll give detailed steps to reproducing this problem, so we can narrow the causes down as quickly as possible.
Eclipse 3.7.1 (Indigo SR1) for C/C++ Linux Developers, Ubuntu 10.10 64-bits
It all started when I imported an existing project that "makes" just fine on its own: I thought Eclipse would help considerably in navigating the files and figuring out what does what. However, some of the #included system headers seemed not to be having the correct effect in Eclipse's view. This was very puzzling, and in the course of investigating this, I managed to recreate the problem in a tiny sand box.
Step one: Create a new C project (File: New: C Project) using the Hello World ANSI C Project sample. The parameters are Executable: Hello World ANSI C Project/Linux GCC, the remaining Empty projects set to Linux GCC, and GNU Autotools set to Hello World ANSI C Autotools Project. Call it "hello". Be sure to generate the makefile automatically (Advanced Settings, I believe it is the default).
Step two: Adjust the include path. Using Project: Properties: C/C++ General: Paths and Symbols: Includes: GNU C, set the search path to /usr/local/include, /usr/lib/gcc/x86_64-linux-gnu/4.4.5/include, /usr/include. The second path depends on the exact version of gcc you have installed. This doesn't matter too much, as long as the build path includes at least /usr/include.
Now if you open hello.c, it looks very simple, and Eclipse is quite happy except for return EXIT_SUCCESS;, which cannot resolve EXIT_SUCCESS. Replace EXIT_SUCCESS with a zero (0) and Eclipse gives the all-clear. Select Project: Build Project to generate the executable.
Open a command-line window and drill down to your Eclipse workspace folder's hello/Debug subfolder. Once there, you can run the executable with the line ./hello.
Now the fun begins. Modify hello.c to read in its latter part:
#include <fcntl.h>
int main(void) {
printf("Hello World!\n");
int zz = SPLICE_F_MOVE;
printf("zz (SPLICE_F_MOVE) is '%d'\n", zz);
printf("Bye World!\n");
return 0;
}
You'll get an error on the int zz... line: "Symbol 'SPLICE_F_MOVE' could not be resolved". If you Build the project, you'll get a similar error in the console view: "error: 'SPLICE_F_MOVE' undeclared".
Now if you change the preamble to:
#define _GNU_SOURCE
#include <fcntl.h>
You still get the error on the int zz line (in the editor), but the project will Build correctly! You can confirm this by running the binary in the command-line window you opened earlier. This is really odd since examination of /usr/include/fcntl.h will show that it #includes <bits/fcntl.h>, and that latter header #defines SPLICE_F_MOVE (and a bunch of others) in a block guarded by #ifdef __USE_GNU (__USE_GNU gets #defined if _GNU_SOURCE is #defined). Why on Earth isn't our #define _GNU_SOURCE properly propagated in the workspace perspective?
So this is my problem in a nutshell: why is it the editor (and all of Eclipse CDT) reports an error (apparently by refusing to process correctly an include), but that the underlying build succeeds?
I had similar problems working with GNU and non-GNU compliant toolchains for cross-compiling various microcontrollers. CDT reports lots of errors, but the actual build works perfectly, even when all the header includes are correctly located in the project settings.
The problem is in how CDT operates as distinct from your make system build. CDT is a standalone lexer, parser, and preprocessor and doesn't make use of the toolchain you're using to do the build. This normally would work fine once you set the project settings to match those generated as command-line arguments to your build tools, but many toolchains frequently include hidden implicit defines as part of their compiler/preprocessor itself. The documentation for the implict/hidden defines is usually sketchy and incomplete in my experience, making it nearly impossible to determine which defines are set for a given toolchain (sometimes even dependent on build options) and what they mean. While it may look like you have all the correct defines set to reach the one you're having a problem with, I usually find (especially with GNU) that there are some you're missing that prevent the switch from being processed the way you expected.
When I debug something like this, I first make sure any headers in my project directory are found first if they have names matching those in other directories, then I slowly start moving headers from the standard include folder to my project folder. CDT doesn't do a very good job of indicating which possible versions of a header file it's parsing first, and it frequently pulls system environment settings when you least expect it, but it does look in your project folder for headers first (if you haven't set the system headers path in your project settings to take precedence). By moving the system headers from the location you're looking at to your project directory, you know for sure exactly which header file is being parsed by CDT. Furthermore, if you rebuild your index after doing the move, then open the file in Eclipse, CDT will indicate what switches it believes are enabled or disabled by greying-out or folding the branches not enabled in the header. Following this process has solved this exact problem for me every time, revealing when I had paths to multiple copies of the same header, accidentally duplicated headers, had defines or includes under unexpected switches, etc.
I have the same issue, but didn't even do anything that complicated to produce it--I just made a hello world project of the type you describe and get the same error. Note that, however, in my case, it may be due to a borked install of cygwin--for instance, I had other errors concerning failing to include the .h files, and a complete deletion/reinstall of cygwin removed those errors but the 'Symbol ... Could not be resolved' error remains.
I then decided to make a second such project, and they both report such an error in the 'problems' view, but only one of the projects actually shows the error underlined etc. in the editor (!)
Maybe this issue comes from Ijndigo itself. Did you tried the same with the latest Indigo SR2? I opened a number of bugs for Indigo and its SR1 in eclipse bugzilla.

How do I link libraries in Xcode 4?

I'm a complete beginner to Apple's Xcode, but I have followed the Xcode documentation and the advice of a few related questions without success.
I installed GMP to /usr/local/bin, wrote a short program using the library, and compiled with gcc main.c -lgmp. It compiled with no warnings or errors, and the executable worked flawlessly.
I started a new Xcode project (Command Line Tool; Type: C), copied the code to the newly created main.c, and opened the project build settings. From there I set Linking > Other Linker Flags to -lgmp and Search Paths > Library Search Paths to /usr/local/bin. However, the build fails with the preprocessor error "Gmp.h: No such file or directory".
I have tried almost every header imaginable:
#include "gmp.h"
#include <gmp.h>
#include "gmp"
#include "libgmp.a" . . .
This has been my main obstacle over the last three months which has prevented me from learning C. Any help leading me to an eventual solution would be greatly appreciated.
There's a few things you have to set up in your Xcode project. For example, I have gmp installed in /opt/gmp/5.0.2 and I will use that as an example. The actual library is installed into /opt/gmp/5.0.2/lib and the header files into /opt/gmp/5.0.2/include. When installing the library setting the --PREFIX flag to /opt/gmp/5.0.2 would handle this automatically. If you don't set this flag the prefix is usually set to /usr/local by default.
The Other Linker Flags looks right, it should be the name of the library.
Set the Header Search Path to the include directory, in my case /opt/gmp/5.0.2/include.
Set the Library Search Path to the lib directory, in my case /opt/gmp/5.0.2/lib.
Since the header search path has been set, you should now be able to include the header file like this:
#include <gmp.h>
Of course, replace /opt/gmp/5.0.2 with the PREFIX path you used when you installed gmp.
Lastly, you typically don't install libraries to /usr/local/bin, you would install to /usr/localand let any binaries be installed into bin while libraries like these would be installed into lib. Of course any path scheme would work, I usually recommend /opt/<project-name>/<version-number> since it allows me to keep better track of what I have installed and have multiple versions of the same libraries and tools without having to deal with collisions.
I have updated my system from snow leopard to mountain lion and had to install gmp.
First of all I have installed Xcode CommandLineTools set.
Secondly, installed Homebrew. Then with it I have done steps in this topic: https://apple.stackexchange.com/questions/38222/how-do-i-install-gcc-via-homebrew
In my last step, made changes to an xcode project as colleague Marcus Karlsson told.
It's finally working! Very big Thank You :)

Resources