LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   c compiler (https://www.linuxquestions.org/questions/linux-newbie-8/c-compiler-878651/)

archie101 05-03-2011 05:56 PM

c compiler
 
i was wandering if there was any good c compilers that are free for linux?

markush 05-03-2011 06:09 PM

mh, I think you should read more in the manuals for your system. Every Linux-distribution comes with gcc, most distributions install it by default.

Markus

MTK358 05-04-2011 07:28 AM

The standard compiler for Linux is GCC (it's free and open-source). It should be in pretty much every distro's package repository.

Quote:

Originally Posted by markush (Post 4345594)
Every Linux-distribution comes with gcc, most distributions install it by default.

I thought that most distros don't have any compilers by default.

markush 05-04-2011 07:33 AM

Hello

@MTK358: thanks, maybe I was wrong.

I helped archie101 in several threads here at LQ, he's using Arch and should not have any problems finding gcc (I don't indeed remember if it is installed by default ;) ).

Markus

MTK358 05-04-2011 08:22 AM

Quote:

Originally Posted by markush (Post 4346163)
(I don't indeed remember if it is installed by default

It asks you during installation.

The package for all the development tools is called "base-devel". I'd recommend that the OP installs this instead of just GCC individually.

archie101 05-05-2011 03:02 PM

I have it installed but i do not know how to open it up and write a program. i looked on archlinux.org and did not find out how to.

markush 05-05-2011 03:06 PM

You will have to write a C-program with your favorite text-editor (i.e. vim ;) ) and then compile it
Code:

gcc -o myprogram myprogram.c
where myprogram.c is the name of the sourcefile and the name after the -o option is the name of the compiled outputfile. You may look here: http://pages.cs.wisc.edu/~beechung/ref/gcc-intro.html

Markus

honeybadger 05-05-2011 03:14 PM

Write a simple c program. Then compile it using gcc -o <progname.o> <progname.c>.
You can also compile it straightaway with gcc <progname>. In this case the compiled binary name would be a.out.
You can then execute the compiled binary using ./<progname.o> or ./<a.out>.
Hope this helps.
PS: AFAIK _all_ distros come with gcc - unless you specifically did not install it. You can check that with 'whereis gcc'.

TobiSGD 05-05-2011 03:16 PM

Quote:

Originally Posted by archie101 (Post 4347706)
I have it installed but i do not know how to open it up and write a program. i looked on archlinux.org and did not find out how to.

I think that you are confusing a compiler with an IDE (Integrated Development Environment). A short look at the Arch repositories showed up a lot of IDEs for Arch, just try a few if you want.

archie101 05-05-2011 03:56 PM

i made a file put a simple c program in it saved it and ran gcc -o nameofmyprogram nameofmyprogram.c and it said gcc: error: hello.c: No such file or directory
gcc: fatal error: no input files
compilation terminated

markush 05-05-2011 04:02 PM

if your program is hello.c, you should try
Code:

gcc -o hello hello.c
Markus

archie101 05-05-2011 04:02 PM

and this is my program to anyone who knows c and might find an error with it:

#include <stdio.h>
#include <conio.h>

int main(void) {

printf("hello");

getch();

}

markush 05-05-2011 04:06 PM

you should use code-tags for programtext in your posts.

If you delete the line #include <conio.h> and the getch() line it will compile and run.

archie101 05-05-2011 04:58 PM

now it says hello.c:3:10: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’

and how do i use code-tags?

markush 05-05-2011 05:03 PM

You may use the "Go Advanced" button at the bottom of your new post, then you end up in an advanced editor where there is this # character where you can click in order to wrap code-tags around the text.

You may as well use the "quote" button for any post where someone used code-tags and see how it works.

Markus


All times are GMT -5. The time now is 09:26 AM.