Why the new generated exec file needs './'

Discussion in 'C Programming' started by fl, Oct 21, 2010.

  1. fl

    fl Guest

    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
    fl, Oct 21, 2010
    #1
    1. Advertising

  2. In article <>,
    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/
    Edward A. Falk, Oct 21, 2010
    #2
    1. Advertising

  3. fl

    Seebs Guest

    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 /
    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.
    Seebs, Oct 21, 2010
    #3
  4. fl

    Jorgen Grahn Guest

    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 .
    Jorgen Grahn, Oct 23, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hal Vaughan
    Replies:
    11
    Views:
    1,075
    Gordon Beaton
    May 22, 2006
  2. tedsuzman
    Replies:
    2
    Views:
    7,051
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  3. Ted
    Replies:
    1
    Views:
    443
    Duncan Booth
    Jul 22, 2004
  4. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    839
    Mark Rae
    Dec 21, 2006
  5. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,681
    Smokey Grindel
    Dec 2, 2006
Loading...

Share This Page