Error in Makefile: gcc: error: filename.o :No such file or directory found

17,055

The compiler doesn't find the object files, because they are not built. And the object files are not built, because the sources are in a different directory (e.g. src) or make doesn't see them for some other reason.


I investigated this a bit more with --debug

make --debug=v -f makefile.gcc

and get

Reading makefiles...
Reading makefile `makefile.gcc'...
Updating goal targets....
Considering target file `all'.
File `all' does not exist.
Considering target file `coder'.
File `coder' does not exist.
Considering target file `coder.o'.
File `coder.o' does not exist.
Considering target file `typedef.h'.
Finished prerequisites of target file `typedef.h'.
No need to remake target `typedef.h'.
Considering target file `basic_op.h'.
Finished prerequisites of target file `basic_op.h'.
No need to remake target `basic_op.h'.
...
Considering target file `count.h'.
Finished prerequisites of target file `count.h'.
No need to remake target `count.h'.
Pruning file `cod_main_fx.h'.
Finished prerequisites of target file `coder.o'.
Must remake target `coder.o'.
Successfully remade target file `coder.o'.
Considering target file `agc2.o'.
File `agc2.o' does not exist.
Pruning file `cnst_fx.h'.
Pruning file `acelp_fx.h'.
Pruning file `typedef.h'.
Pruning file `basic_op.h'.
...
Finished prerequisites of target file `homing.o'.
Must remake target `homing.o'.
Successfully remade target file `homing.o'.
Finished prerequisites of target file `coder'.
Must remake target `coder'.
gcc -Wall -g -O4 -DWMOPS=0 -D__MSDOS__ -o coder coder.o agc2.o autocorr.o ...
gcc: error: coder.o: No such file or directory
gcc: error: agc2.o: No such file or directory
gcc: error: autocorr.o: No such file or directory

Because of the header file dependencies, make thinks it has properly remade the object file targets, even though it doesn't see the source files.

If you provide a source file (even an empty one), the output looks a little bit different

...
Finished prerequisites of target file `coder.o'.
Must remake target `coder.o'.
gcc -Wall -g -O4 -DWMOPS=0 -D__MSDOS__ -c coder.c
Successfully remade target file `coder.o'.
Considering target file `agc2.o'.
File `agc2.o' does not exist.
Pruning file `cnst_fx.h'.
...

Here you can see, how make checks all the prerequisites and then rebuilds the object file, using the implicit rule given in the makefile.

You can avoid make's confusion, by listing the source file as a dependency explicitly, e.g.

coder.o: coder.c

Make will then complain about the missing source file without invoking the link command

make: *** No rule to make target `coder.c', needed by `coder.o'. Stop.

Share:
17,055
nprak
Author by

nprak

Updated on June 04, 2022

Comments

  • nprak
    nprak almost 2 years

    I have the following makefile but I get error when I compile it as: No such file or directory found. Here is the makefile I am trying to execute: P.S. I am trying to execute this on Linux and windows both but same error I get on both of them.

    CC = gcc
    #LFLAG = 
    CFLAGS = -Wall -g -O4 -DWMOPS=0 -D__MSDOS__
    
    # Objects
    OBJ =  coder.o agc2.o autocorr.o az_isp.o bits.o c2t64fx.o c4t64fx.o cod_main.o \
        convolve.o cor_h_x.o d2t64fx.o d4t64fx.o decim54.o dec_main.o deemph.o \
        dtx.o d_gain2.o gpclip.o g_pitch.o hp6k.o hp7k.o hp50.o hp400.o hp_wsp.o \
        int_lpc.o isfextrp.o isp_az.o isp_isf.o lagconc.o lag_wind.o levinson.o \
        lp_dec2.o math_op.o ph_disp.o pitch_f4.o pit_shrp.o pred_lt4.o preemph.o \
        p_med_ol.o qisf_ns.o qpisf_2s.o q_gain2.o q_pulse.o random.o residu.o \
        scale.o syn_filt.o updt_tar.o util.o voicefac.o wb_vad.o weight_a.o \
        basicop2.o count.o log2.o oper_32b.o homing.o \
    
    DOBJ =  decoder.o agc2.o autocorr.o az_isp.o bits.o c2t64fx.o c4t64fx.o cod_main.o \
        convolve.o cor_h_x.o d2t64fx.o d4t64fx.o decim54.o dec_main.o deemph.o \
        dtx.o d_gain2.o gpclip.o g_pitch.o hp6k.o hp7k.o hp50.o hp400.o hp_wsp.o \
        int_lpc.o isfextrp.o isp_az.o isp_isf.o lagconc.o lag_wind.o levinson.o \
        lp_dec2.o math_op.o ph_disp.o pitch_f4.o pit_shrp.o pred_lt4.o preemph.o \
        p_med_ol.o qisf_ns.o qpisf_2s.o q_gain2.o q_pulse.o random.o residu.o \
        scale.o syn_filt.o updt_tar.o util.o voicefac.o wb_vad.o weight_a.o \
        basicop2.o count.o log2.o oper_32b.o homing.o \
    
    # Implicit Rules
    .c.o:
        $(CC) $(CFLAGS)  -c  $<
    
    all:    coder decoder
    
    # Explicit Rules
    coder:    $(OBJ)
        $(CC) $(CFLAGS) -o coder $(OBJ)
    decoder:  $(DOBJ)
        $(CC) $(CFLAGS) -o decoder $(DOBJ)
    
    # Individual File Dependencies
    
    basicop2.o: typedef.h basic_op.h count.h
    count.o:    typedef.h count.h
    log2.o:     log2.h typedef.h basic_op.h count.h log2_tab.h
    oper_32b.o: typedef.h basic_op.h oper_32b.h count.h
    autocorr.o: typedef.h basic_op.h oper_32b.h acelp_fx.h count.h
    az_isp.o:   typedef.h basic_op.h oper_32b.h count.h
    bits.o:     typedef.h basic_op.h cnst_fx.h bits_fx.h acelp_fx.h count.h dtx_fx.h
    c2t64fx.o:  typedef.h basic_op.h math_op.h acelp_fx.h count.h cnst_fx.h
    c4t64fx.o:  typedef.h basic_op.h math_op.h acelp_fx.h count.h cnst_fx.h q_pulse_fx.h
    cod_main.o: typedef.h basic_op.h oper_32b.h math_op.h cnst_fx.h acelp_fx.h \
        cod_main_fx.h bits_fx.h count.h
    convolve.o: typedef.h basic_op.h count.h
    cor_h_x.o:  typedef.h basic_op.h math_op.h count.h
    d2t64fx.o:  typedef.h basic_op.h count.h cnst_fx.h
    d4t64fx.o:  typedef.h basic_op.h count.h cnst_fx.h q_pulse_fx.h
    decim54.o:  typedef.h basic_op.h acelp_fx.h count.h cnst_fx.h
    dec_main.o: typedef.h basic_op.h oper_32b.h cnst_fx.h acelp_fx.h dec_main_fx.h  bits_fx.h  count.h  math_op.h 
    deemph.o:   typedef.h basic_op.h math_op.h count.h
    dtx.o:      typedef.h basic_op.h oper_32b.h math_op.h cnst_fx.h acelp_fx.h bits_fx.h dtx_fx.h count.h log2.h
    d_gain2.o:  typedef.h basic_op.h oper_32b.h math_op.h log2.h cnst_fx.h acelp_fx.h count.h 
    gpclip.o:   typedef.h basic_op.h count.h 
    g_pitch.o:  typedef.h basic_op.h math_op.h count.h 
    homing.o:   typedef.h basic_op.h cnst_fx.h bits_fx.h
    hp400.o:    typedef.h basic_op.h oper_32b.h acelp_fx.h count.h 
    hp50.o:     typedef.h basic_op.h oper_32b.h cnst_fx.h acelp_fx.h count.h 
    hp6k.o:     typedef.h basic_op.h acelp_fx.h count.h cnst_fx.h 
    hp_wsp.o:   typedef.h basic_op.h oper_32b.h acelp_fx.h count.h 
    int_lpc.o:  typedef.h basic_op.h cnst_fx.h acelp_fx.h count.h 
    isfextrp.o: typedef.h basic_op.h oper_32b.h cnst_fx.h acelp_fx.h count.h 
    isp_az.o:   typedef.h basic_op.h oper_32b.h count.h cnst_fx.h 
    isp_isf.o:  typedef.h basic_op.h count.h 
    lagconc.o:  typedef.h basic_op.h count.h cnst_fx.h acelp_fx.h 
    lag_wind.o: typedef.h basic_op.h oper_32b.h 
    levinson.o: typedef.h basic_op.h oper_32b.h acelp_fx.h count.h 
    lp_dec2.o:  typedef.h basic_op.h count.h cnst_fx.h 
    math_op.o:  typedef.h basic_op.h math_op.h count.h 
    ph_disp.o:  typedef.h basic_op.h cnst_fx.h acelp_fx.h count.h 
    pitch_f4.o: typedef.h basic_op.h math_op.h acelp_fx.h cnst_fx.h count.h 
    pit_shrp.o: typedef.h basic_op.h count.h 
    pred_lt4.o: typedef.h basic_op.h count.h 
    preemph.o:  typedef.h basic_op.h count.h 
    p_med_ol.o: typedef.h basic_op.h acelp_fx.h oper_32b.h count.h math_op.h 
    qisf_ns.o:  typedef.h basic_op.h acelp_fx.h count.h 
    qpisf_2s.o: typedef.h basic_op.h cnst_fx.h acelp_fx.h count.h 
    q_gain2.o:  typedef.h basic_op.h oper_32b.h math_op.h count.h log2.h acelp_fx.h 
    q_pulse.o:  typedef.h basic_op.h count.h q_pulse_fx.h 
    random.o:   typedef.h basic_op.h count.h 
    residu.o:   typedef.h basic_op.h count.h 
    scale.o:    typedef.h basic_op.h count.h 
    syn_filt.o: typedef.h basic_op.h math_op.h count.h cnst_fx.h 
    updt_tar.o: typedef.h basic_op.h count.h 
    util.o:     typedef.h basic_op.h count.h 
    voicefac.o: typedef.h basic_op.h math_op.h count.h 
    wb_vad.o:   cnst_fx.h wb_vad_fx.h typedef.h basic_op.h count.h math_op.h wb_vad_c_fx.h 
    weight_a.o: typedef.h basic_op.h count.h 
    agc2.o:     cnst_fx.h acelp_fx.h typedef.h basic_op.h count.h math_op.h 
    hp7k.o:     typedef.h basic_op.h cnst_fx.h acelp_fx.h count.h 
    decoder.o:  typedef.h basic_op.h acelp_fx.h cnst_fx.h main.h bits_fx.h dtx_fx.h count.h 
    coder.o:    typedef.h basic_op.h acelp_fx.h cnst_fx.h cod_main_fx.h bits_fx.h   count.h cod_main_fx.h 
    

    THE Exact ERROR I am getting is this:

    make -f makefile.gcc
    gcc -Wall -g -O4 -DWMOPS=0 -D__MSDOS__ -o coder coder.o agc2.o autocorr.o az_isp.o bits.o c2t64fx.o c4t64fx.o cod_main.o convolve.o cor_h_x.o d2t64fx.o d4t64fx.o decim54.o dec_main.o deemph.o dtx.o d_gain2.o gpclip.o g_pitch.o hp6k.o hp7k.o hp50.o hp400.o hp_wsp.o int_lpc.o isfextrp.o isp_az.o isp_isf.o lagconc.o lag_wind.o levinson.o lp_dec2.o math_op.o ph_disp.o pitch_f4.o pit_shrp.o pred_lt4.o preemph.o p_med_ol.o qisf_ns.o qpisf_2s.o q_gain2.o q_pulse.o random.o residu.o scale.o syn_filt.o updt_tar.o util.o voicefac.o wb_vad.o weight_a.o basicop2.o count.o log2.o oper_32b.o homing.o 
    gcc: error: coder.o: No such file or directory
    gcc: error: agc2.o: No such file or directory
    gcc: error: autocorr.o: No such file or directory
    gcc: error: az_isp.o: No such file or directory
    gcc: error: bits.o: No such file or directory
    gcc: error: c2t64fx.o: No such file or directory
    gcc: error: c4t64fx.o: No such file or directory
    gcc: error: cod_main.o: No such file or directory
    gcc: error: convolve.o: No such file or directory
    gcc: error: cor_h_x.o: No such file or directory
    gcc: error: d2t64fx.o: No such file or directory
    gcc: error: d4t64fx.o: No such file or directory
    gcc: error: decim54.o: No such file or directory
    gcc: error: dec_main.o: No such file or directory
    gcc: error: deemph.o: No such file or directory
    gcc: error: dtx.o: No such file or directory
    gcc: error: d_gain2.o: No such file or directory
    gcc: error: gpclip.o: No such file or directory
    gcc: error: g_pitch.o: No such file or directory
    gcc: error: hp6k.o: No such file or directory
    gcc: error: hp7k.o: No such file or directory
    gcc: error: hp50.o: No such file or directory
    gcc: error: hp400.o: No such file or directory
    gcc: error: hp_wsp.o: No such file or directory
    gcc: error: int_lpc.o: No such file or directory
    gcc: error: isfextrp.o: No such file or directory
    gcc: error: isp_az.o: No such file or directory
    gcc: error: isp_isf.o: No such file or directory
    gcc: error: lagconc.o: No such file or directory
    gcc: error: lag_wind.o: No such file or directory
    gcc: error: levinson.o: No such file or directory
    gcc: error: lp_dec2.o: No such file or directory
    gcc: error: ph_disp.o: No such file or directory
    gcc: error: pitch_f4.o: No such file or directory
    gcc: error: pit_shrp.o: No such file or directory
    gcc: error: pred_lt4.o: No such file or directory
    gcc: error: preemph.o: No such file or directory
    gcc: error: p_med_ol.o: No such file or directory
    gcc: error: qisf_ns.o: No such file or directory
    gcc: error: qpisf_2s.o: No such file or directory
    gcc: error: q_gain2.o: No such file or directory
    gcc: error: q_pulse.o: No such file or directory
    gcc: error: random.o: No such file or directory
    gcc: error: residu.o: No such file or directory
    gcc: error: scale.o: No such file or directory
    gcc: error: syn_filt.o: No such file or directory
    gcc: error: updt_tar.o: No such file or directory
    gcc: error: util.o: No such file or directory
    gcc: error: voicefac.o: No such file or directory
    gcc: error: wb_vad.o: No such file or directory
    gcc: error: weight_a.o: No such file or directory
    gcc: error: homing.o: No such file or directory
    make: *** [coder] Error 1
    
  • MadScientist
    MadScientist about 9 years
    I don't see how this could be true. The object files are listed as prerequisites of the target according to this makefile; therefore if make can't find them or build them it will report an error, it won't try to build the target.
  • Olaf Dietsche
    Olaf Dietsche about 9 years
    Just try and see for yourself. Create a directory with just the makefile and needed header files and run make. You will see exactly OP's (gcc's) error message.
  • nprak
    nprak about 9 years
    I also debugged it ans it seems there is problem in c file which is not able to make the object file. Thank you for you time and help.