Sign in to follow this  
Questionmark02

programming in linux

Recommended Posts

Questionmark02    122
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?

Share this post


Link to post
Share on other sites
Questionmark02    122
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...

Share this post


Link to post
Share on other sites
Kwizatz    1392
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!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
owl    376
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.

Share this post


Link to post
Share on other sites
Questionmark02    122
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. :)

Share this post


Link to post
Share on other sites
flangazor    516
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.

Share this post


Link to post
Share on other sites
supagu    148
i also installed anjuta seems to work although i had to fudge the includes to get it working with multiple c++ files.

i would like to know how to make Makefile's though, but there seem no good tuts on the topic. Any links fellas?

or recommended books

Share this post


Link to post
Share on other sites
igni ferroque    415
You should use extensions for files. I'm almost positive that the C specification even requires the .c extension for code files. IDE's are overrated. You can also use <code>make filename.o</code> or <code>make filename</code> to automagically run the compiler (I think this is GNU make only). The next step, of course, is learning makefile syntax. It's really easy.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this