programming in linux

Started by
10 comments, last by igni ferroque 19 years, 4 months ago
hey, i just recently moved to linux, so i'm no hardcore-user. however, i can't get a simple "hello world"-programm going... i was wondering if any of you guys could nudge me in the right direction... i don't know how to compile! i created a file named "test", a simple ascii-text: int main() { return 0; } that, of course, wont do nothing but should be enough of a program to compile. "gcc test" in the terminal however will tell me that the file format is not recognised. what am i supposed to do?
Advertisement
What about naming it test.c ?
g++ -o out test
hm. seems to work...
just didn't think it would be *that* simple. ;)
i also thought that linux (and thus, it's programs as well) dont care if there is a .txt oder something at the end of a file name.
ah well.

embarrasing...
Quote:Original post by Anonymous Poster
g++ -o out test

this one doesnt work. still unrecognized file format.
try renaming test to test.c then:

gcc test.c -o test

then run test with:

./test

GCC recognices source files by their extension, running the apropiate compiler (C,C++,fortran,java,ada,objc) and linker (ld) as needed.

because whether a file can be executed or not is not infered by its extension but rather as an attribute flag, executable files do not require an extension, datafiles most of the time do.

Cheers!
Take a look at the man-page for gcc ("man gcc"). There is a -x command-line option that allows you to specify the source language. So, in your example, "gcc -x c test" would compile test as a C file.
OP: In the near future you'll probably want to install some development enviroment for XFree (linux's graphical UI) to handle larger projects than helloworlds.

If you're a Visual Studio user, try "MinGW Studio" which is a clone of the first and doesn't needs you to write makefiles.
[size="2"]I like the Walrus best.
i've got anjuta now up and running. still need to get used to it a little, i guess, but it seems fine so far.
it just seemed wrong to start programming in linux without getting a simple file compiled by hand first. ;)
i'm still setting everything up on this system really. but it seems everything's stable now and i've got all i need, so i guess i should move on now and get some programming done.
thanks for all the great replies, by the way. :)
I disagree, owl. I think that IDE's distract. I guess they might be useful if the beginner isn't a shell or elisp hacker so he can't home brew his tools when he needs them.

This topic is closed to new replies.

Advertisement