How do you compile a c program in atom editor - c

I downloaded atom a couple of days ago and I can't seem to find the right package or where and how you compile the program.
does anyone know?

Now, it's possible to run and compile (also debug) C and C++ program from within atom editor.
Install gpp compiler package in atom editor.
Prerequisites:
Windows:
You'll need to install MinGW and add it to your system PATH.
Mac:
You'll need to install XCode.
Linux:
The GNU Compiler Collection may come with your distribution. Run which gcc g++ to find out.
To compile and run: F5
To debug: F6

Atom is "simply" a Text editor that is not able to compile anything. If you use a Makefile, then there are a few add-ons for building targets via key bindings.
If not, open a terminal and use the C compiler on your system. On Linux/Unix machines you probably want to use gcc:
gcc <your_source>.c -o <output_name>
EDIT
Or take a look at This Package

here's a link for atom gnu gcc compiler-- https://atom.io/packages/gpp-compiler
1. download it
2. place the file in atom's package folder
3. press F5 on atom editor to RUN n Compile your file.
it will open text.ext as a output.

Related

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.

Install GTK for c on Windows 10?

Can you tell me how to install GTK on windows 10 or have a step by step guide, all the ones I've tried have not helped me.
Possibly if someone also explain how to compile from cmd or prepare an IDE (code: block maybe).
Any commands I mention should be run at the MINGW shell, found here: C:\msys64\msys2_shell.cmd
First update msys2 with pacman -Syu
Make sure you have installed GCC...Install the required toolchain for GCC with pacman -S mingw-w64-x86_64-toolchain. When using pacman, just keep typing enter if prompted to follow through with the installation and get back to the command prompt.
In order to set this step up with Code:Blocks, make sure you go to the Code:Blocks menu Settings->Compiler, and the menu Toolchain Executables. From there, put in the msys2 installation directory and where you installed MinGW's GCC compiler (for me this was putting C:\msys64\mingw64) under the compiler's installation directory option. Also edit the C Compiler path under the same menu to x86_64-w64-mingw32-gcc.exe.
Next, in order to install gtk+3.0, use the command pacman -S mingw-w64-x86_64-gtk3. Now the latest version of GTK+3.0 will have been installed, so it is time to set it up with Code:Blocks.
Open Code:Blocks and create a new C file. You may definitely write your code in Code:Blocks, but I do not suggest that you compile it from there. Two compile, go back to the MINGW shell. Type nano ~/.bashrc to edit it. You may scroll down using the arrow keys to the bottom of the file and add: PATH=$PATH:/c/msys64/mingw64/bin. Restart the MINGW shell and open it back up.
Finally, try running:
gcc source.c -o executable.exe `pkg-config --cflags --libs gtk+-3.0`.
If that command doesn't work, I would suggest using the i686 version of gcc installed in MINGW.
I hope this helps!

Compiling an MPI program with mingw and MPICH2 in eclipse juno

Ive been trying to setup mpich2 to compile some programs using MPI on windows 7. The problem that I encounter is that it wont create the binary files when I build a project.
I use the stadard mpi program to test (hello world) and I get this message after building it:
13:33:29 ** Rebuild of configuration Debug for project mpitest **
Info: Internal Builder is used for build mpiCC "-IC:\MPICH2\include"
-O0 -g3 -Wall -c -fmessage-length=0 -o "src\mpitest.o" "..\src\mpitest.c"
The Open MPI wrapper compiler was unable to find the specified
compiler cl.exe in your PATH.
Note that this compiler was either specified at configure time or in one of several
possible environment variables.
13:33:29 Build Finished (took 78ms)
I tried to search for cl.exe but it doesn't exist. I have to say that I also installed openMPI but I didn't use it cause the cluster that I am gonna target run the program is using MPICH2. I have already installed 32bit minGW, 32bit MPICH2 and 32bit openMPI.
Is it normal to not create binaries since i run the .c file in the cluster? If its normal how am i going to check if the program is ok even for 1 process?
Thanks in advance! Cheers!
I found the answer by luck... In the project preferences, select C/C++ build-> Tool Chain editor-> choose cygwin and its done. For some reason i had mingw in that option and wouldnt create binaries, i suppose it needs some other tools that can be found only in the cygwin and not mingw... Still trying to set it and run on the cluster... so many options :/

How do I compile a .c file on my Mac?

How do I compile a .c file on my Mac?
You'll need to get a compiler. The easiest way is probably to install XCode development environment from the CDs/DVDs you got with your Mac, which will give you gcc.
Then you should be able compile it like
gcc -o mybinaryfile mysourcefile.c
You will need to install the Apple Developer Tools. Once you have done that, the easiest thing is to either use the Xcode IDE or use gcc, or nowadays better cc (the clang LLVM compiler), from the command line.
According to Apple's site, the latest version of Xcode (3.2.1) only runs on Snow Leopard (10.6) so if you have an earlier version of OS X you will need to use an older version of Xcode. Your Mac should have come with a Developer Tools DVD which will contain a version that should run on your system. Also, the Apple Developer Tools site still has older versions available for download. Xcode 3.1.4 should run on Leopard (10.5).
In 2017, this will do it:
cc myfile.c
Just for the record in modern times,
for 2017 !
1 - Just have updated Xcode on your machine as you normally do
2 - Open terminal and
$ xcode-select --install
it will perform a short install of a minute or two.
3 - Launch Xcode. "New" "Project" ... you have to choose "Command line tool"
Note - confusingly this is under the "macOS" tab.
Select "C" language on the next screen...
4- You'll be asked to save the project somewhere on your desktop. The name you give the project here is just the name of the folder that will hold the project. It does not have any importance in the actual software.
5 - You're golden! You can now enjoy c with Mac and Xcode.
You can use gcc, in Terminal, by doing gcc -c tat.c -o tst
however, it doesn't come installed by default. You have to install the XCode package from tour install disc or download from http://developer.apple.com
Here is where to download past developer tools from, which includes XCode 3.1, 3.0, 2.5 ...
http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wo/5.1.17.2.1.3.3.1.0.1.1.0.3.3.3.3.1
Ondrasej is the "most right" here, IMO.
There are also gui-er ways to do it, without resorting to Xcode. I like TryC.
Mac OS X includes Developer Tools, a developing environment for making
Macintosh applications. However, if someone wants to study programming
using C, Xcode is too big and too complicated for beginners, to write
a small sample program. TryC is very suitable for beginners.
You don't need to launch a huge Xcode application, or type unfamiliar
commands in Terminal. Using TryC, you can write, compile and run a C,
C++ and Ruby program just like TextEdit. It's only available to
compile one source code file but it's enough for trying sample
programs.
Use the gcc compiler. This assumes that you have the developer tools installed.
STEP 1
Just check wheater your MacBook has the compiler or not using this command 👉🏻 clang --version in your command line interface. If the tool exists then you will be able to see the version like this
STEP 2
Next, go to the directory where your source code exists using CMD Interface, then run the command make "filename" without the .c extension.
STEP 3
The final command to run your source code after compiling it is ./filename without the .c extension.
This is how you can compile and run your program on the Macintosh system.

How to compile a C program?

I haven't done C in a long time. I'd like to compile this program, but I have no idea how to proceed. It seems like the makefile refers to GCC a lot and I've never used GCC.
I just want an executable that will run on windows.
You may need to install either cygwin or mingw, which are UNIX-like environments for Windows.
http://www.mingw.org/
http://www.cygwin.com/
When downloading/installing either cygwin or mingw, you will have the option of downloading and installing some optional features; you will need the following:
gcc (try version 2.x first, not 3.x)
binutils
GNU make (or gmake)
If it requires gcc and you want it to run on Windows, you could download Cygwin.
That's basically an emulator for GNU/Linux type stuff for Windows. It works with an emulation DLL.
http://www.cygwin.com/
In order to compile this program you need a C compiler. It does not have to be gcc, although you are already given a makefile set up to use gcc. The simplest thing for you to do would be the following:
Install cygwin
Open the cygwin command prompt
go into the directory where you have your makefile
type 'make'
That should compile your program
If you are not comfortable with using command line tools then you can download the free version of MS Visual Studio and import the source files into a new Visual Studio project. This way you would not need to install cygwin and use gcc, but you would need to know how to create projects and run programs in Visual Studio.
You almost certainly don't need all of cygwin to compile using gcc. There are plenty of standalone gcc clones for Windows, like gcw.
If it's reasonably portable C code (I haven't looked at it), then you may be able to just ignore the included Makefile and feed the source into whatever compiler you do want to use. What happens when you try that?
Dev-C++ provides a simple but nice IDE which uses the Mingw gcc compiler and provides Makefile support. Here are the steps I used to build the above code using Dev-C++ (i.e. this is a "how-to")
After downloading the source zip from NIST, I
downloaded and installed the Dev-C++ 5 beta 9 release
created a new empty project
added all the .c files from sts-2.0\src
Then under Project Options
added -lm in the Linker column under Parameters
added sts-2.0\include to the Include Directories in Directories
set the Executable and Object directories to the obj directory under the Build Options
and then hit OK to close the dialog. Go to Execute > Compile and let it whirl. A minute later, you can find the executable in the sts-2.0\obj directory.
First, there is little chance that a program with only makefiles will build with visual studio, if only because visual studio is not a good C compiler from a standard POV (the math functions in particular are very poorly supported on MS compilers). It may be possible, but it won't be easy, specially if you are not familiar with C. You should really stick to the makefiles instead of trying to import the code in your own IDE - this kind of scienfitic code is clearly meant to be compiled from the command line. It is a test suite, so trying things randomly is NOT a good idea.
You should use mingw + msys to install it: mingw will give you the compilers (gcc, etc...) and msys the shell for the make file to run correctly. Contrary to one other poster, I would advise you against using gcc 2 - I don't see any point in that. I routinely use gcc 3 (and even 4) on windows to build scientific code, it works well when the code is unix-like (which is the standard platform for this kind of code).

Resources