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

Wim Sturkenboom 05-05-2011 06:06 PM

[code]some code here[/code]
will result in
Code:

some code here
And we can not tell you what's wrong without seeing the new program ;)

archie101 05-05-2011 06:42 PM

my program is
Code:

#include <stdio.h>

int main(void) {

printf("hello");

}

and the error is
Code:

gcc: error: c.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.

do i have to take the .c off?

sorry for my knowing nothingness i am used to using a windows compiler.

TobiSGD 05-05-2011 06:52 PM

gcc can't find your file. Did you specify the right path to your source code?

MTK358 05-05-2011 07:17 PM

Quote:

Originally Posted by archie101 (Post 4347866)
[/CODE] and the error is
Code:

gcc: error: c.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.

do i have to take the .c off?

sorry for my knowing nothingness i am used to using a windows compiler.

Do you know the extremely basic concepts such as the current directory and relative paths (note that it's not really programming-related, but very important for doing anything in the command line)? If not, read this before continuing: http://linuxcommand.org/

honeybadger 05-07-2011 03:50 AM

Well, this is speculation but it looks like there is a compiler but nothing to compile.
I would suggest going into the directory that has the c.c file and then executing gcc c.c. Else provide the full path name eg 'gcc /home/name/dir/c.c'.
Hope this helps.

Nermal 05-07-2011 05:22 AM

Hi Archie101;

OK, your code, the content of "hello.c":
Code:

#include <stdio.h> /* include the headers that have printf in them */

int main(int argc, char *argv[]) /* correctly call the main function, yours would work but it will cause a warning when compiling */
{

printf("hello\n");  /* the \n puts a new line at the end */

return (0); /* as main has been defined as returning an int then we should really return something */

}

To compile make sure that hello.c is in the current directory:

Code:

bash$ gcc -o hello hello.c
This in the normal world would compile hello.c into an executable of hello

Now if it throwing errors on compile time then the problem is likely that it cannot find the libraries it needs.

Can you check that there is a file called "/usr/lib/libstdc++*" ?

also a quick explanation of how you installed gcc and the Linux version/distribution you are using would help.

kindofabuzz 05-07-2011 06:09 AM

It's not finding it because you're not in the directory that's the c file is in. cd to that dir then run gcc again.

MTK358 05-07-2011 08:06 AM

Quote:

Originally Posted by Nermal (Post 4349096)
Can you check that there is a file called "/usr/lib/libstdc++*" ?

How is that relavent? The OP is using C.


All times are GMT -5. The time now is 12:06 PM.