Can't compile C on windows 7 x64 - c

I have visual studio 2012 ultimate and mingw installed on my pc.
However, when I try to compile any program (I have only tried a simple hello world program)
e.g when I use the visual studio cl compiler or the gcc compiler I get the error :
cl is not recognized as an internal or external command, operable program or batch file.
and similar for mingw-gcc.
I have visual studio installed in the default location. I have installed mingw in D:\MinGw but I have added it to the path variable. Also I have installed CodeBlocks after getting frustrated with this and my program builds and runs easily when I try that from inside CodeBlocks. I can also compile my program from inside Visual Studio by clicking on the build and run buttons.
What do I need to do to compile and run programs from the commandline in windows 7?

Instead of running a "regular" command prompt, run the "Visual Studio command prompt". You can find a link to it in the start menu.
It's essentially the same, but it sets up for you all the environment variables you need for all the VS tools to work from the command line.

Sounds like you still have a path problem. The mingw-gcc path for example would need to be to the bin directory:
D:\MinGW\bin
in your case. Then you should be able to run gcc.

Related

installing GSL library for C programming in windows

I want to install the GSL library (https://www.gnu.org/software/gsl/) in windows. I have downloaded the files but i do not know what to do apart from that in order to be able to use the functions of the library (apart from the #include <...> in my program.c file).
I am using visual studio code and i have installed mingw.
Thanks in advance
EDIT
I am adding more information about this issue. I am not the original poster, but I have the same problem.
I am trying to use the GSL and I work with Visual Studio Code on Windows 10.
I have already installed the basic packages to work with C/C++ in
Visual Studio Code. More precisely, if I am not wrong, VS Code is
using the compiler gcc.exe from mingw64 (last version). This was
installed using an 'extension' available at VS Code (https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools).
I downloaded the last version of the GSL (2.7) and unzipped it.
I get stuck when I try to follow the installation instructions. When I
execute either .\configure or ./configure in the DOS command line,
I get an error of "unknown command" (even if I am placed in the same directory where the file is stored).
When I execute .\configure in PowerShell, I get a message asking me
which programme should be used to open this file.
And here is where I get lost. :/
I have discovered an alternate path, which is installing GSL from vcpkg (https://vcpkg.io/). This is suggested by VS Code, actually. This vcpkg seems to be a programme by Microsoft to make it easier to install third-party C/C++ packages in Windows.
The specifications to install vcpkg are (https://vcpkg.io/en/getting-started.html):
Windows 7 or newer
Git
Visual Studio 2015 Update 3 or newer
I can try this path, but first I would like to be sure there is no easier way (installing Visual Studio to not really use it seems a lot to me!).

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.

New to C: Compiling in Visual Studio Code... error: gcc not recognized?

I am very new to coding (trying to teach myself C). I have some experience with MatLab, but I understand it is very different from C. I have Windows 10 with the newest version of Visual Studio Code (VSC) with the Run Code Extension and git extension (not sure what git does, but VSC prompted me to install). I am now familiar with the text editor, but do not know how to compile/run my code (apologies if I'm butchering the terminology, again, a newby). One friend recommended I determine the location in which the desired text file is located, type "gcc filename.c", enter, type "./a.out", and then the program should run. (Said friend has a Mac and I supposed the execution commands are different?) Regardless, I encountered "Run Code" extension on my google adventures and follow the steps I've seen online, but I am still getting the error pictured.
I can see how this would be an especially basic question, but if anyone can offer assistance/advice, I would be extremely grateful!
Thanks, All.
Sandy
P.S. In case the image doesn't load/work for whatever reason, this is the error:
"'gcc' is not recognized as an internal or external command,
operable program or batch file."
Works perfect in Visual Code. You need the following:
C/C++ extension in Visual Code.
msys64 installed in C:\
Add path to msys64 bin folder in environment variable
Instructions:
https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools
Important the msys64 path doesn't contain spaces so don't install it in Program Files.
You can search "Edit system environment variables" from the windows button, press button Environment Variables, and then add it as a System variable "Path". For me its located in
C:\msys64\mingw64\bin
Hey,,,
It will work for you I believe
Blockquote
First: open the link: https://www.msys2.org/
Go to the installation and download the installer .. install the exe file.
search mingw in windows search(windows start)
there is an app named--> MSYS2 MinGW {64/32}-bit
run it as administrator
Found command shell ---> type: pacman -Syu
Will ask you for some installation click on Y
Then again go to the same app MSYS2 MinGW {64/32}-bit and run as admin
and write--> pacman -Ss gcc (in shell that opend after click)
after clicking there will be bunch of things and now you have to care about your windows arch.. if it is 64 bit then write---> pacman -S mingw-w64-x86_64-gcc (and if its 32 you will find something like that where 64 will replaced by 32 in bunch of commands that are showing in your shell)
after executing this command gcc will be installed in your system to check write: gcc --version || g++ --version
After that to install the debugger write pacman -S mingw-w64-x86_64-gdb
to check write: gdb --version
**Every thing got installed in your system now find the mingW file or mysys2 file on C drive(whereever you r mingW file got saved) go the the minGW 64 || 32 accroding to your operating system there is a bin folder click on that and copy the path inside the bin folder and save it in environment variables path **
Blockquote
Enjoy vs code
My recommendation
You are on Windows right? So you can just install Visual Studio IDE (follow this tutorial). Which is better than vs code. This tutorial is for C++ but it works for C as well. Because C++ uses the same compiler as C but with some more things(simple explanation).
The solution for your problem
You are getting the massage 'gcc' is not recognized as an internal or external command, operable program or batch file because you do not have the gcc compiler installed on your computer. But if you want to install it, you can follow this tutorial. But I highly recommend you use Visual Studio IDE which I mentioned above.
Type gcc --version in the command prompt to check whether the C compiler is installed in your machine.
If it is installed then try adding gcc to the environment variables using this link:
https://www.youtube.com/watch?v=qLh84CmdBJ0
If it is not installed then install it using instructions using this link:
https://www.guru99.com/c-gcc-install.html
and then add it to the environment variables using the link above.
If it is installed and not recognized by VSCode then try to run VSCode from CMD by typing code in CMD.

Can ARM desktop programs be built using visual studio 2012?

I was working with visual studio 2012 beta and my desktop (win32) program compiled fine in ARM architecture.
After upgrading to visual studio 2012 RC, the compiler would not work and spews out the following error:
"Compiling Desktop applications for the ARM platform is not supported"
I found a forum post on this
http://connect.microsoft.com/VisualStudio/feedback/details/745580/arm-configuration-doesnt-work
Is it correct that Microsoft is really cutting off win32 development on ARM?
And that compiling in VS2012 beta was just a fluke?
You can edit the file:
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Platforms\ARM\Microsoft.Cpp.ARM.Common.props
In the <PropertyGroup> section add the line:
<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>
before </PropertyGroup>
And that's all, you can build ARM desktop apps with VS2012.
I was able to get around that error and compile a little "hello world" cpp file for ARM by adding the "/D _ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE" command-line argument to the ARM version of cl at C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_arm. I found that #define from sn0w's answer on this question in the crtdefs.h file, without having to modify that file. Now, I can't guarantee that anything more complex will actually work, or that Microsoft hasn't instituted some sort of whitelisting or digital signature verification for Windows RT desktop apps, so even though it may compile, it may not be allowed to run when Windows RT is finally available.
Note that before you can run the ARM version of cl.exe from the command line, you must set the environment variables using this batch file: "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_arm\vcvarsx86_arm.bat"
Even if you compile the app, you won't be able to run it on Windows 8 RT as unsigned apps will not start.
I just tested this, and unfortunately it is the case.
You receive the following message:
Windows cannot verify the digital signature of this file
I imagine there is probably a work around for this, but it will never be officially supported.
yes of course. i practised with VS2012 RC.
now i'll explain how to avoid "Compiling Desktop applications for the ARM platform is not supported" and build win32 application.
1st way: fix build tools - the goal is to patch (or try to substitute it with beta's one) MSBuild's lib: Microsoft.Build.CPPTasks.Common.v110.dll
2nd way: run the "VS2012 ARM Cross Tools Command Prompt" from Visual Studio Tools start menu, then execute cl [cl params] myfile1.cpp myfile2.cpp myres.res ... /link [linkparams]
for both this cases you also need to commentout an #error directive in crtdefs.h on line 332. (Microsoft Visual Studio 11.0\VC\include)

Compiling C with Emacs on windows system

I have a little bit of C programming experience from school, but it was all Unix. I want to compile some C with Emacs, using Emacs as a second IDE.
What is the easiest way to go about doing this? I downloaded Cygwin with no successful compile of a helloWorld.c in Emacs. Even opening the cygwin command prompt (shell or whatever its called), it doesn't recognize gcc as a command.
Error
'make' is not recognized as an internal or external command, operable program or batch file.
I need a compiler that works on Windows, is free (or comes with visual studio), and can be used with Emacs. What to type into Emacs after the M-x compile command would be nice to know too. I looked at MinGW, but downloading it is a chore.
I hope the question makes sense. I often get lost in the open source world.
Environment
Windows XP, Visual Studio 2010, Emacs 23.2.1, Windows 7.1 SDK installed, Cygwin
I use Visual Studio as a compiler with emacs as an editor.
Just install Visual Studio C++ 2010 Express Edition.
Then what I do is write an nmake Makefile and invoke nmake from
the Visual Studio Command Prompt (accessible from the Programs menu).
This works fine for smaller projects.
See http://msdn.microsoft.com/en-us/library/f35ctcxw.aspx
for more details.
For larger projects you can create a solution in Visual Studio and
just use emacs as an editor. You can also invoke msbuild from the
command prompt to build the solution.
Also, the visual studio command prompt just invokes vcvars.bat (or something like it)
to set up the necessary environment. I guess you might be able to modify the emacs shell to point to an instance of cmd that has run this bat file on startup?
Anything of this sort you attempt to do on windows is going to be a "chore" because you are trying to put together components from distinct sources. If you want easy, use an IDE and compiler packaged together, such as the Visual Studio freebie edition, or Code Blocks, or Dev C++, etc.
My understanding is that the M-x compile prompt is looking for a shell command, in the path of the shell that emacs runs which you can of course set somewhere. Depending on what build of emacs you have for windows, that might by default by the windows shell, or it could be bash under MINGW or cygwin.
To get gcc and make and such under cygwin you have to select these from the cygwin packages to install (using the cygwin installer efficiently is an an obscure skill in itself). Cygwin's gcc will by default compile things to depend on the cygwin dll, but you can also make mingw-style windows executables with the -mno-cygwin flag to gcc or by running mingw's gcc rather than cygwin's.
Presumably emacs could even launch the Visual Studio compiler if you figure out an appropriate command line for that, or its make utility, or you could run it from gnu make. Issues you are likely to run into when mixing and matching are windows vs unix paths, having your executable path include the necessary tools, and the likelihood that a foreign compiler may format errors in a way that the IDE won't parse to make them clickable. All of these things can be worked around (for example, during one phase of a project I had a sed script that reformatted GCC-cross errors to make them clickable in Visual Studio's compiler errors window)
You don't need gcc or cygwin to compile C code on Windows.
I use the compiler, make utility, linker, and other tools that come with the (free) Microsoft Visual-C++ Express edition and the (free) Windows SDK, within emacs 23.2.
Some tips for you:
use this in your .emacs file:
(eval-after-load "compile"
'(progn
(setq compilation-scroll-output "first-error")
(setq-default compile-command "nmake ")))
Add appropriate error message regexii to the compilation error regexp list.
Like this:
(mapcar
(lambda (x)
(add-to-list 'compilation-error-regexp-alist-alist x))
(list
;; Microsoft C/C++:
;; keyboard.c(537) : warning C4005: 'min' : macro redefinition
;; d:\tmp\test.c(23) : error C2143: syntax error : missing ';' before 'if'
;; .\cppcli1.cpp(36): error C2059: syntax error : 'public'
;; e:\projects\myce40\tok.h(85) : error C2236: unexpected 'class' '$S1'
;; myc.cpp(14) : error C3149: 'class System::String' : illegal use of managed type 'String'; did you forget a '*'?
;; ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) ?\: \\(error\\|warning\\) C[0-9]+:" 1 3)
'(msvc "^[ \t]*\\([A-Za-z0-9\\.][^(]*\\.\\(cpp\\|c\\|h\\)\\)(\\([0-9]+\\)) *: +\\(error\\|fatal error\\|warning\\) C[0-9]+:" 1 3)
))
(setq compilation-error-regexp-alist
(mapcar 'car compilation-error-regexp-alist-alist))
I am new to Emacs, Cygwin Bash, and general C terminology so I found some of the other explanations in this thread and others a bit confusing for me to follow. I eventually found a solution on my own. For those who are in a similar situation, I hope these simple instructions help. If anyone more advanced than I has additions to add I can update this post.
Install Cygwin.
On the setup screen go into the "devel" folder. Select "gcc-core" if it has not already been downloaded into your Cygwin setup. Finish installation.
Install Emacs.
Find the .emacs file (the Emacs configuration file, located for me in the main Emacs folder) and add in the following:
(setq explicit-shell-file-name "{Path to Cygwin folder}\\Cygwin.bat")
(setq shell-file-name "bash")
(setenv "SHELL" shell-file-name)
Set your own path to Cygwin.bat where indicated. Note that you must use Cygwin.bat. It does not appear to work if you go straight to bash.exe. Also, you may need to use double backslashes to get the escape characters to work or Emacs may complain at startup.
Now you can test if it works by going into Emacs and typing M-x shell. It should bring up the Cygwin bash shell in a new buffer.
As an example, compile and execute the program "foo.c" through Cygwin Bash:
Compile: gcc foo.c -o foo.exe. This builds the file and makes an executable with the same name.
Execute: ./foo.exe. The output should be shown in Emacs shell buffer.
This has worked very well for me and I hope this will be a simple alternative for those that don't want to go through configuring Visual Studio or other solutions.

Resources