Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Why the new generated exec file needs './'

Reply
Thread Tools

Why the new generated exec file needs './'

 
 
fl
Guest
Posts: n/a
 
      10-21-2010
Hi,
I am new to makefile. The original C source can be compiled and the
exec runs well. Now, I want to change a module distribute.c to
distribute0.c for some minor modification to make a comparison. See
the following makefile with the comments place (i.e. I change
distribute.c to distribute0.c, the same to distribute.o). I find that
the new exec file is not recognized at the Bash of Linux. It says:


If 'make-ldpc' is not a typo you can use command-not-found to lookup
the package that contains it. like this:
cnf make-ldpc.

Although it can run with the './' prefix, I want to know the reason
for this new requirement. Thanks.



..................
COMPILE = cc -c -O # Command to compile a module from .c to .o
LINK = cc # Command to link a program


# MAKE ALL THE MAIN PROGRAMS. First makes the modules used.


progs: modules
$(COMPILE) make-ldpc.c
$(LINK) make-ldpc.o mod2sparse.o mod2dense.o mod2convert.o \
rcode.o rand.o alloc.o intio.o open.o distrib.o -lm -o make-
ldpc
# changed to distrib0.o


# MAKE THE TEST PROGRAMS. First makes the modules used.


# MAKE THE MODULES USED BY THE PROGRAMS.


modules:
$(COMPILE) alloc.c
$(COMPILE) intio.c
$(COMPILE) blockio.c
$(COMPILE) check.c
$(COMPILE) open.c
$(COMPILE) distrib.c # changed to
distrib0.c
$(COMPILE) -DRAND_FILE=\"`pwd`/randfile\" asm_rand.c

 
Reply With Quote
 
 
 
 
Edward A. Falk
Guest
Posts: n/a
 
      10-21-2010
In article <1cf855ae-1ff2-4c10-a917->,
fl <> wrote:

>Although it can run with the './' prefix, I want to know the reason
>for this new requirement. Thanks.


I don't think this has anything to do with the C language in particular;
write a python program and see if the same thing doesn't happen.

When you execute a program by name only, the system searches for the
program in the directories listed in $PATH. If not found, then the
program won't be executed.

If you specify the program to execute by explicit path, e.g. "./foo"
instead of "foo", then the system will execute the program from the
location you specified instead of searching for it.

If your $PATH contains "." then the system will also search your current
directory for the program and your program goes away.

However, putting "." in your path is discouraged for security reasons.

--
-Ed Falk,
http://thespamdiaries.blogspot.com/
 
Reply With Quote
 
 
 
 
Seebs
Guest
Posts: n/a
 
      10-21-2010
On 2010-10-21, fl <> wrote:
> Although it can run with the './' prefix, I want to know the reason
> for this new requirement. Thanks.


The reason is that, on Unix-like systems, the current directory is
not automatically searched for programs, so if a program is in your
current directory, but not in $PATH, it won't be found if you don't
specify the path to it.

This has nothing to do with C, nor with your makefile. Redirecting to
comp.unix.shell.

Key point: DO NOT try to change this behavior. If you put the current
directory in your path, you will get badly screwed over some day, and it
will be your own damn fault.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      10-23-2010
On Thu, 2010-10-21, fl wrote:
> Hi,
> I am new to makefile. The original C source can be compiled and the
> exec runs well. Now, I want to change a module distribute.c to
> distribute0.c for some minor modification to make a comparison. See
> the following makefile with the comments place (i.e. I change
> distribute.c to distribute0.c, the same to distribute.o). I find that
> the new exec file is not recognized at the Bash of Linux. It says:
>
>
> If 'make-ldpc' is not a typo you can use command-not-found to lookup
> the package that contains it. like this:
> cnf make-ldpc.


Huh? The bash shell says that? It doesn't on any system I've ever used.

[Makefile snipped]

Anyway, this is offtopic, but that Makefile is pretty broken, and can be
simplified a lot. Assuming Gnu Make:

-------------
asm_rand.o: CPPFLAGS+=-DRAND_FILE=\"`pwd`/randfile\"
CFLAGS=-O

make-ldpc: mod2sparse.o
....
make-ldpc: distrib.o
make-ldpc: make-ldpc.o
$(CC) $(CFLAGS) -o $@ $^
-------------

It still lacks 'make all' and 'make clean' targets, sane compiler
options (if you're using gcc, you are currently running with most
warnings disabled) and real dependencies (I guess you have header
files?).

Read the manual to learn more. (And remember that although most C
programmers need to know Make or else get hurt a lot, it's really
offtopic here.)

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Runtime.exec(String[]) Doesn't Always Work, bBut Runtime.exec(String) Does Hal Vaughan Java 11 05-22-2006 04:49 PM
exec "statement" VS. exec "statement in globals(), locals() Ted Python 1 07-22-2004 08:51 AM
exec "statement" VS. exec "statement" in globals(), locals() tedsuzman Python 2 07-21-2004 08:41 PM
Backup Exec 9.1: The Backup Exec job engine system service is not responding Christian Falch Computer Support 1 06-23-2004 02:22 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57