Why the new generated exec file needs './'

F

fl

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
 
E

Edward A. Falk

fl said:
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.
 
S

Seebs

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
 
J

Jorgen Grahn

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top