Cannot open source file "stdio.h" in Visual Studio Code - c

I'm new to C and this is my first project using visual studio. I have #include <stdio.h> in the first line of the code but there is an error "cannot open source file "stdio.h" C/C++ (1696)". I have installed the Microsoft C/C++ extension. I am happy to clarify anything. Thank you!

Note:
Be aware that VSCode is simply an editor. With some extensions installed, it may help you code "faster & easier".
Solution:
But in order for you to compile the code it is less beginner friendly than IDEs like CodeBlocks.
The way I do it is by going to :
Terminal > New terminal
cd "the_directory_in_which_the_file.c_exists" (don't forget the double quotes)
gcc "file.c"
./a.out (./a.exe on Windows)
Just in case:
if gcc (the compiler in this case) is not installed, then you can quickly do so by following this article's steps if you use Windows, or this one if you are on Linux.

Related

How to use VC++ compiler in command line(Windows)?

I tried to use VC++ commandline, instead of MinGW compiler for windows system programming. I wrote a simple hello world program and tried to compile it, then i got this error message.
test2.c(1): fatal error C1083:'stdio.h': No such file or directory
I also added "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\Hostx86\x86" directory (where c1.dll lives) to the System Envionment Variable(PATH).
How can I fix this issue? Other tutorials don't give much information about VC++. (A lot of MinGW compiler tutorial out there btw)
You should use visual studio command line if you want to compile or run program with the help of vc++ compiler.
Else all information related to setting environment variables ETC. resides in this MSDN document.

regex.h in dev-c++ (windows )

I am trying to use regex in a c program. i am using windows 10 and Dev-C++ . whenever i add header file for regex i.e.
#include <regex.h>
it gives me error
[error] regex.h: NO such file or directory.
i couldn't figure out how to download and install regex library for c in dev-c++. compiler: TDM-GCC 4.9.2 64-bit Release. Thanks for your help.
I assume there something wrong with the include path during the compilation process. There is a nice expanation of the compilation process of c/c++ applications over here, in case you're interested.
Basically, when compiling a c/c++ application, your compiler, in a first step, scans your source files and replaces all #include <file.h> with the content of file.h it finds in its search path.
Dev-c++ uses MinGW and a port of the GNU compiler collection (gcc) for the compilation process.
Now what you have to do:
Figure out whether regex.h is included in your MinGW installation (Check /usr/include.)
Adapt the include path in dev-c++
Sadly I don't have a computer running Windows nearby making it hard to help with these two steps. To install regex on MinGW this package seems promising.

Using fork() with VS 2013 and Cygwin

I am trying to write a C program that will use fork() and wait() in Visual Studio 2013. I have downloaded and installed Cygwin, but I am unable to configure Visual Studio to use the appropriate header files. I'm fairly new to the IDE and I was wondering if this community could help me figure out where I am making a mistake.
When starting a new project, this is what I do:
Create new Visual C++ Win32 Console Application
Add new main.c source file to the project
Right-click project properties and configure Include Directories to
include the Cygwin directory: C:\cygwin64
I've taken a screenshot of where I am trying to configure the properties in case this is where I am making my mistake:
My code is rather simple as I am just trying to get it to run at this point:
#include <unistd.h>
int main() {
int i;
i = fork();
if (i == 0) {
printf("I am the child.");
}
else {
wait(&i);
}
}
Here's a screenshot of the error message I receive when I try to build my project:
I apologize in advance if this is a silly question, but I do appreciate any help that you can offer. If there is anything that I can do on my end to help troubleshoot, please let me know.
The problem is that your current include path C:\cygwin64\bin is equivalent to unix /bin, which is for binaries (aka executables). To use unix headers, you need to use the equivalent of /usr/include, which, for your system, should be C:\cygwin64\usr\include.
Using fork() within a Win32 Console application is not going to work. It's a Unix system call. Cygwin is an emulation of the Linux environment that runs on top of Win32.
As others have said you need to be using the Cygwin toolchain to do your compile and builds.
There may be third party libraries to allow Visual Studio to cross-compile for Cygwin, but a Win32 console application is definitely not what you want if you re making Unix system calls.
Ok, there are lots of pieces here to do this, and there are also a lot of answers here with incorrect information.
First, as some have said, you need to modify your include path to contain your include folder from Cygwin, from your install that appears to be C:\Cygwin64\usr\include.
Next, there is an FAQ on this very thing on the Cygwin site. How do I use cygwin1.dll with Visual Studio or MinGW?
From the page:
Use the impdef program to generate a .def file for the cygwin1.dll (if
you build the cygwin dll from source, you will already have a def
file)
impdef cygwin1.dll > cygwin1.def
Use the MS VS linker (lib) to generate an import library
lib /def=cygwin1.def /out=cygwin1.lib
Create a file "my_crt0.c" with the following contents
#include <sys/cygwin.h>
#include <stdlib.h>
typedef int (*MainFunc) (int argc, char *argv[], char **env);
void my_crt0 (MainFunc f) {
cygwin_crt0(f);
}
Use gcc in a Cygwin prompt to build my_crt0.c into a DLL (e.g. my_crt0.dll).
Follow steps 1 and 2 to generate .def and .lib files for the DLL.
Download crt0.c from the cygwin website and include it in your
sources. Modify it to call my_crt0() instead of cygwin_crt0().
Build your object files using the MS VC compiler cl.
Link your object files, cygwin1.lib, and my_crt0.lib (or whatever you
called it) into the executable.
Note that if you are using any other Cygwin based libraries that you
will probably need to build them as DLLs using gcc and then generate
import libraries for the MS VC linker.

Setting up the compiler Open watcom in windows XP

I installed the compiler "Open watcom" on my OS Win XP, which I run under Virtual Box.
I installed program in automode: full package and with auto changes to autoexec and config files, where all needed info for environment variables was inserted during installation.
I can`t compile C project for DOS 16 bits, I get the error :
WxD WDEBUG.386 not present.
I tried to modify "system.init" file and inserted "device=c:\watcom\binw\wdebug.386 " in [386enh] directory (it was adviced in FAQ in one of the sites related to open watcom), but that gave no effect.
I need help! What should I do to make c projects compile and resolve issue with wdebug.386
Thanks in advance!
One problem I have had in the past is that Watcom doesn't like spaces in the path. This does not appear to be your problem but I recommand you to at least eliminate it as a possible cause.
I overcame this problem by installing Watcom in a special program directory which I call Programx.
So this is what I suggest you do:
Uninstall Watcom
Create a subdirectory "Programx" under "C:\"
Re-install Watcom such that its root is "C:\Programx\Watcom"
Good luck! In case you don't already know it, Watcom produces excellent Win32 code.
I have never had such issues with OW.
I have installed it either using the default configuration or choosing the host OS as Windows. With that configuration OW by default creates Win32 apps. If you want to create DOS apps, you need to invoke the compiler in a special way.
This is what works for me on Windows 7 64-bit:
// file: hw.c
// compile with Open Watcom C/C++ 1.9 under Windows: wcl -q -bt=DOS hw.c
#include <stdio.h>
int main(void)
{
printf("Hello world!\n");
return 0;
}
And then I can successfully run hw.exe in DosBox using the command dosbox hw.exe. In Windows XP you can run hw.exe directly.
If it's of any help, these are the environment variables related to OW on my system:
EDPATH=C:\WATCOM\EDDAT
INCLUDE=C:\WATCOM\H;C:\WATCOM\H\NT;C:\WATCOM\H\NT\DIRECTX;C:\WATCOM\H\NT\DDK
Path=...;C:\WATCOM\BINNT;C:\WATCOM\BINW;...
WATCOM=C:\WATCOM
WHTMLHELP=C:\WATCOM\BINNT\HELP
WIPFC=C:\WATCOM\WIPFC

wascana eclipse simple C code Launch failed no binaries found

I am new to Eclipse CDT. I did some online search but I got lost. I installed MinGW (works fine with command window), then I installed Eclipse Helios wascana. I did add path/enviroment to Properties->C/C++ build -> enviroment (C:\MinGW\bin)
Eclipse underlines
#include <stdlib.h>
#include
#include
unresolved inclusion. I guess I did not link it to MinGW libraries.
Can anyone help?
In my case, I did the following: Properties->C/C++ Build -> Tool Chain Editor then I chose MinGw GCC as the current toolchain. It looks like it works now. Give it a show
Go to:- properties> C/C++ Build> Tool Chain Editor>
then, select :-
Current Tool chain as --> Cygwin GCC
and,
Current builder as --> CDT Internal Builder
it worked for me. hope it will work for u and others as well!! :)
EDit : for linux users
I got this error even when the compiler was certanly ok, so only build/rebuild (sometimes) and starting new project could help. May be it's not your case, but Eclipse "loves" this error so much, that's wat i found out about it

Resources