Compile C code in atom for Mac


#1

I was trying to look for a solution to compile code in Atom using packages, but I think there is not such a package yet. In my Mac, I can compile code using the following line on the terminal:

gcc name.c -o name

So I was wondering if there is way to make Atom use the terminal to compile the code and show the results. Thanks!


#2

Have you tried the build package?


#3

Not yet. How do I install it?


#4

Like any other package. See the documentation here:

https://atom.io/docs/v1.0.0/using-atom-atom-packages


#5

Thanks! I’ll try it here.


#6

Now, there is another problem. How to solve this?


#7

You’d have to check the documentation of the build package. I haven’t used it but I did do a quick read and it said that you could describe custom build tools.


How do I run my code in Atom?
#8

I guess compilers and build configurations, are one of those areas that haven’t seen a lot of package development yet, which some users who are coming from full fledged IDEs are still missing.


#9

@filipebcs I am the author of the package. It recognizes a few builds as seen in the readme. If you have a Makefile which builds your project, it would automatically detect this and invoke make to build your project.

If you use something less standard, you can compose a file named .atom-build.json which defines how you build your project. It would look something similar to this:

{
  "cmd": "gcc",
  "args": [ "-o", "myProgram" ]
}

Of course, you can add additional arguments, or execute another command, even another script. It supports detecting errors in the output and automatically go to that location in your code if you provide the errorMatch key. All keys are documented in the readme linked to above.

Let me know if you have any other issues.


#10

Is there any way that I can make a generic build file that will build any C file with any name? Thanks very much for the answer!


#11

Basically, the idea is that you have a C project and then you have a Makefile that describes how to build it, and all Atom needs to do is to invoke make. Then all the hard work goes into writing the right Makefile. This is a topic not related to Atom, however.

On many machines, make is even preconfigured so that even with an empty Makefile, you can do

make foo

And this will compile foo.c and produce an executable foo from it.


#12

The package that I use to compile and run C/C++ codes in atom is the gpp-compiler package by kriscross07.

Refer this for more details: https://atom.io/packages/gpp-compiler.

Thanks


#13

OK! I’ll try that. Thank you!