Teen Programmers Unite  
 

 

Return to forum top

C[++] Programming in Linux

Posted by 142857 [send private reply] at October 21, 2002, 03:12:54 PM

I wrote and compiled a C and a C++ program in my Red Hat Linux, and the same thing happened both times. I'll give you the C example. I wrote a really simple program called "trial.c", saved it, etc., then compiled it with "gcc", I think. No object files were left. Then, I said "a.out", expecting the program to run, but it just said that "a.out" was an invalid command, even though when I said "ls" it showed "a.out". Any suggestions? Thanks.

Posted by Neumann [send private reply] at October 21, 2002, 03:15:33 PM

./a.out will run it

gcc trial.c -o trial will produce an executable file called trial which you can run using ./trial

You can put "." in your path and you will no longer need to type ./ before the names of local executables.

Posted by 142857 [send private reply] at October 21, 2002, 04:45:57 PM

Wow. That was .easy. .Thanks, .Neumann.

What do you mean put "." in your path? Thanks

Posted by Psion [send private reply] at October 21, 2002, 07:51:06 PM

Linux doesn't search your current directoy for executables to run by default, but rather only /bin, etc.. It's some sort of security measure. "." means the current directoy. Add it to the PATH environment variable (see a FAQ if you don't know the details of this) if you don't like this measure.

Posted by mop [send private reply] at October 21, 2002, 07:58:37 PM

but "/" doesn't mean execute, how does that work?

Posted by ItinitI [send private reply] at October 21, 2002, 09:00:39 PM

'Cause Linus said so! Um, no, that's not it. Dot, '.', this directory, then slash, '/', this file? [Maybe?].

Posted by buzgub [send private reply] at October 22, 2002, 12:55:47 AM

. means the current folder, and to reference a file in a folder you put a slash after the foldername. To access the file foo in the folder bar, you'd do "foo/bar". To get the file thwop in the folder "." you do "./thwop".

I hope that makes it clear.

Posted by unknown_lamer [send private reply] at October 22, 2002, 08:51:38 AM

Do not put . in your PATH. If you really want to, then put it at the end so it is searched last. This can open up all sorts of insecurities (e.g. someone puts a trojaned program in the current dir and you run it). If . is at the beggining of the path, and someone puts a trojaned 'ls' in the dir, you can't even see what is in the dir without running the trojan. Bad Stuff.

Posted by Psion [send private reply] at October 22, 2002, 11:10:04 AM

Of course you can see what's in the directory: just run /bin/ls.

Posted by unknown_lamer [send private reply] at October 22, 2002, 01:35:47 PM

But that requires more typing! Heresy!

Posted by 142857 [send private reply] at October 22, 2002, 02:55:51 PM

ah, i see.

Posted by mop [send private reply] at October 22, 2002, 07:56:07 PM

in the end though, you'd be typing the "./" less, so that would make up for the extra "/bin/".

That means we've been wasting our time all along!

Posted by unknown_lamer [send private reply] at October 22, 2002, 09:35:33 PM

But then you'd be adding extra insecurity.

Posted by mop [send private reply] at October 22, 2002, 09:40:11 PM

I tried not to make that look serious.
I suck.

Posted by taubz [send private reply] at October 23, 2002, 04:11:12 PM

Of course, if it's your own machine, then what are the chances someone has put a trojan ls in one of your directories?

Posted by mop [send private reply] at October 23, 2002, 05:28:08 PM

well, you could be an idiot

Posted by DragonWolf [send private reply] at October 24, 2002, 04:21:37 AM

*looks up, noticing everyone look at him after mops last post*

What?

Posted by unknown_lamer [send private reply] at October 24, 2002, 08:30:55 AM

Someone could root your box and install a trojan ls.

Posted by sphinX [send private reply] at October 24, 2002, 06:09:10 PM

I don't see why typing './' is such a problem, the keys are right next to each other (on QWERTY keyboards anyway, I have no idea where they'd be on something like DVORAK).

Posted by mop [send private reply] at October 24, 2002, 06:36:22 PM

I meant you'd be an idiot for the reason Unknown_lamer pointed out. Whatever, I need to quit it with the cookie dough.

Posted by gian [send private reply] at October 24, 2002, 08:04:58 PM

unknown_lamer, if they could root your box, why would they bother with a trojan?

Posted by unknown_lamer [send private reply] at October 25, 2002, 11:01:10 PM

For future access? Maybe you won't have been rooted, but they gained user level access, and then installed a trojaned ls in the user's home directory. When you go to see what files are in the dir and you have . first in your PATH, then oops the trojaned ls is not running as root and can do stuff like start another program as root and notify the cracker that they now have root, among other things.

Posted by mop [send private reply] at October 26, 2002, 11:29:06 AM

Lots of home linux users can be quite careless as well..

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.