PDA

View Full Version : writting programs on linux



Micko
11-25-2005, 02:53 AM
Hello, guys, today I've installed linux mandrake 9.0 I want to write my first line of code under linux platform. Since i don't know anything about linux I cannot find gcc compiler on it. Can you suggest any good IDE with compiler (C/C++) which I can download and install on linux system?
Thanks

kermit
11-25-2005, 05:05 AM
I would imagine that gcc is installed already - you could find out by doing:

whereis gcc

or

gcc -v

Anyway, if you did not install it, go back to your install disc and do it that way. As for an IDE, try KDevelop - you might have some troubles though, with your libraries being ancient (Mandrake 9 is quite old now). Personally, I think Emacs makes a nice IDE, though I know some would not agree with me on that one...

If you are not in to messing around with makefiles, you could just type in your source to a text editor of your choice, and then invoke the compiler from the command line, something like so:

gcc -Wall -o your_prog your_prog.c

This tells gcc to crank up the warnings (Wall) and call your program your_prog (If you don't use -o name then your executable file will be called 'a.out' by default). If you want to run the program through gdb, then use the -ggdb option as well.

Micko
11-25-2005, 10:36 AM
Thanks,
i have found gcc.
Now my problem is how to use it to get .exe file. For example I have source code file named Prvi.c

I tried "gcc Prvi.c" but all I get is a.out, and that I cannot run.
I installed linux yesterday and have no prior experience...
Thanks

7smurfs
11-25-2005, 11:41 AM
To get a specific file:

gcc Prvi.c -o Prvi

then to run it just change directories to where the file Prvi is and then type in ./Prvi at the console.

Micko
11-25-2005, 02:03 PM
Thanks, that was exactly what I wanted...

dwks
11-25-2005, 04:15 PM
I tried "gcc Prvi.c" but all I get is a.out, and that I cannot run.
I thought so too, for a while. But you can:

$ ./a.out

Micko
11-26-2005, 03:30 AM
Yes, I know now, "./" was key to solving my problem

NoUse
11-27-2005, 04:35 AM
"./" solves everybody's problems. :)

kungtotte
11-27-2005, 08:03 AM
tomas@loke:~$ ./end world hunger
-bash: ./end: No such file or directory


Nope :(

jmd15
11-27-2005, 09:07 AM
When I compile, in Knoppix, I use this command:


g++ -Wall input.cpp -o output

Then I can just type output and it will run. However, if I specify an extension(output.out) then I have to use the ./ command. It seems easier and better, at least to me, to leave off an extension so you can just type the name and it will run.

Rashakil Fol
11-27-2005, 06:36 PM
When I compile, in Knoppix, I use this command:


g++ -Wall input.cpp -o output

Then I can just type output and it will run. However, if I specify an extension(output.out) then I have to use the ./ command. It seems easier and better, at least to me, to leave off an extension so you can just type the name and it will run.

Unfortunately (or, if you ask me, fortunately), this is not true of (all) other Linux and Unix distributions.

Sysop_fb
11-28-2005, 10:37 AM
When I compile, in Knoppix, I use this command:


g++ -Wall input.cpp -o output

Then I can just type output and it will run. However, if I specify an extension(output.out) then I have to use the ./ command. It seems easier and better, at least to me, to leave off an extension so you can just type the name and it will run.

./ is not a command it's merely specifying the path of the target you want to reach.

If whatever directory you're currently in isn't specified in the PATH environment variable it won't find it when searching for that executable and you will be required to specify a ./ to signify that it's in your current working directory.

Since CWD is .
And the previous folder is ..
If you want you can add . to the PATH


# uname -a
QNX 1 H 425 PCI 32
# echo $PATH
/bin:/etc:/usr/bin:/etc:/usr/ucb:/usr/local/bin:/qnx4/photon/bin:/usr/bin/photon/
# PATH=$PATH:.
# echo $PATH
/bin:/etc:/usr/bin:/etc:/usr/ucb:/usr/local/bin:/qnx4/photon/bin:/usr/bin/photon/:.

Now it will also search for the executable I'm trying to run from whichever CWD I'm in at the time(as long as it can't find it in any of the other folders in the PATH first since . is at the end)
You may also need to specify 'export PATH=$PATH:.' depends on what you're running.

Jaqui
11-28-2005, 05:36 PM
Mandrake ( now Mandriva ) has released their 2006 edition, this, under old numbering system is version 11.0..at 6 months between releases 9.0 is 4 years old.
most linux distros release at least once a year, unlike ms every 5 years.

I do use an even older version of linux, as the one commercially licensed development tool I have requires the 2.4 kernel toolchain.