Problem running a makefile


 
Thread Tools Search this Thread
Top Forums Programming Problem running a makefile
# 1  
Old 01-14-2013
Problem running a makefile

I have written this makefile and am getting an error saying

Code:
make nfd
gfortran -O -Wall -fbacktrace -fno-align-commons -c -o fd.o fd.f
fd.f:49: Error: Can't open included file 'fd.par'
make: *** [fd.o] Error 1

The directory structure is as follows

Code:
.
├── library
│   ├── fd
│   │   ├── blkdat.f
│   │   ├── fd.com
│   │   ├── fd.doc
│   │   ├── fd.par
│   │   ├── findiff2d.f
│   │   ├── findiff.f
│   │   ├── Makefile
│   │   ├── makefl.fd.old
│   │   ├── misc.f
│   │   ├── model.f
│   │   ├── plt.f
│   │   ├── stencils2d.f
│   │   ├── stencils.f
│   │   └── time.f
│   ├── misc
│   │   ├── 1dvel2.f
│   │   ├── 1dvel.f
│   │   ├── 2dvel.f
│   │   ├── add2.f
│   │   ├── add.f
│   │   ├── anomaly3.f
│   │   ├── anomaly4.f
│   │   ├── anomaly5.f
│   │   ├── anomaly6.f
│   │   ├── anomaly.f
│   │   ├── ave2.f
│   │   ├── ave4.f
│   │   ├── ave.f
│   │   ├── bound.f
│   │   ├── copy.f
│   │   ├── difference2.f
│   │   ├── difference.f
│   │   ├── gmtslice_2d.f
│   │   ├── gmtslice.f
│   │   ├── gmtslicep.f
│   │   ├── h2z.f
│   │   ├── init2.f
│   │   ├── init3.f
│   │   ├── inverse_2d.f
│   │   ├── inverse.f
│   │   ├── inverse_old.f
│   │   ├── ireg_2d.f
│   │   ├── ireg.f
│   │   ├── istop2.f
│   │   ├── istop.f
│   │   ├── lambda2.f
│   │   ├── lambda3.f
│   │   ├── latave.f
│   │   ├── ray.par
│   │   ├── README
│   │   ├── real2int.f
│   │   ├── rec_ascii.f
│   │   ├── rec_binary.f
│   │   ├── rec_deci.f
│   │   ├── rec_diff.f
│   │   ├── rec.f
│   │   ├── rec_noise2.f
│   │   ├── rec_noise.f
│   │   ├── rec_offset.f
│   │   ├── regrid_2d.f
│   │   ├── regrid.f
│   │   ├── resamp.f
│   │   ├── reset.f
│   │   ├── select2.f
│   │   ├── select3.f
│   │   ├── smodel.f
│   │   ├── update.f
│   │   ├── velbuild.f
│   │   ├── velint.f
│   │   ├── vz.f
│   │   ├── xyz2bath.f
│   │   ├── z2h.f
│   │   └── zero.f
│   └── pltlib
│       ├── colors
│       ├── Makefile
│       ├── nopltlib.f
│       ├── pltsub.f
│       ├── xbuplot.c
│       ├── xbuplot_icon
│       └── xpltlib.f
└── programs
    ├── fd.f
    ├── Makefile
    ├── ray.f
    └── zslice.f

Code:
# Set Fortran compiler
fortran_compiler = gfortran

# Set Fortran compiler options
fortran_compiler_opts = -O -Wall -fbacktrace -fno-align-commons -c -o

#---------------------------------------------------------------------------------------------------

# Set C compiler
#c_compiler = gcc

# Set C compiler options
#c_compiler_opts = -c -o

#---------------------------------------------------------------------------------------------------

# Source code paths
prog_dir = ../programs
pltlib_dir = ../library/pltlib
lib_dir = ../library

prog_name = "$(prog_dir)/fd"

# Source object files
nfd_objects= fd.o $(fd_lib)/model.o $(fd_lib)/time.o $(fd_lib)/findiff.o $(fd_lib)/findiff2d.o \
    $(fd_lib)/stencils.o $(fd_lib)/stencils2d.o $(fd_lib)/misc.o $(fd_lib)/plt.o \
    $(fd_lib)/blkdat.o $(plot_lib)/nopltlib.o

# Executable name
#prog_dir = $(program_dir)/nfd

# Rule for generating the .o file by compiling the .f file using the fortran compiler
%.o: %.f
    $(fortran_compiler) $(fortran_compiler_opts) $@ $<

nfd: fd
fd: $(nfd_objects)
    $(fortran_compiler) -o fd1 $(nfd_objects)
    mv fd1 $(prog_dir)

# Dependencies
fd.o         : $(lib_dir)/fd/fd.par $(lib_dir)/fd/fd.com
model.o      : $(lib_dir)/fd/fd.par $(lib_dir)/fd/fd.com
time.o       : $(lib_dir)/fd/fd.par $(lib_dir)/fd/fd.com
findiff.o    : $(lib_dir)/fd/fd.par $(lib_dir)/fd/fd.com
findiff2d.o  : $(lib_dir)/fd/fd.par $(lib_dir)/fd/fd.com
stencils.o   : $(lib_dir)/fd/fd.par $(lib_dir)/fd/fd.com
stencils2d.o : $(lib_dir)/fd/fd.par $(lib_dir)/fd/fd.com
misc.o       : $(lib_dir)/fd/fd.par $(lib_dir)/fd/fd.com
plt.o        : $(lib_dir)/fd/fd.par $(lib_dir)/fd/fd.com
blkdat.o     : $(lib_dir)/fd/fd.par $(lib_dir)/fd/fd.com
 
$(plot_lib)/nopltlib.o: FORCE
    cd $(plot_lib)/pltlib; $(MAKE) $(@F)
#    cd $(@D); $(MAKE) $(@F)
FORCE:


Last edited by kristinu; 01-14-2013 at 08:44 AM..
# 2  
Old 01-14-2013
According to the diagnostics:
Code:
fd.f:49: Error: Can't open included file 'fd.par'

line 49 in fd.f is trying to include a file named fd.par. Either fd.f is expecting this file to be somewhere other than ../library/fd/fd.par or ../library/fd/fd.par has permissions set such that the person running make doesn't have read access.
# 3  
Old 01-14-2013
I have now changed things a little bit

Top directory has

Code:
BUILD_DIR  documents  examples  Makefile  README  sources

The makefile is updated to this

Code:
# Source directory
fd_prgdir = ./sources/programs
fd_libdir = ./sources/library/fd
plot_libdir = ./sources/library/pltlib

# Include directory
 fd_incdir = ./sources/library/fd/include/

# Object directory
obj_dir = ./BUILD_DIR/obj

# Program directory
bin_dir = ./BUILD_DIR/bin

# Set Fortran compiler
fortran_compiler = gfortran

# Set Fortran compiler options
fortran_compiler_opts = -O -Wall -fbacktrace -fno-align-commons -I./sources/library/fd/include -c -o

# Source files
sources = $(fd_prgdir)/fd.f \
    $(fd_libdir)/model.f \
    $(fd_libdir)/time.f \
    $(fd_libdir)/findiff.f \
    $(fd_libdir)/findiff2d.f \
    $(fd_libdir)/stencils.f \
    $(fd_libdir)/stencils2d.f \
    $(fd_libdir)/misc.f \
    $(fd_libdir)/plt.f \
    $(fd_libdir)/blkdat.f \
    $(plot_libdir)/nopltlib.f

includes = $(fd_incdir)/fd.par \
    $(fd_incdir)/fd.com \

# Object files
objects= $(obj_dir)/fd.o \
    $(obj_dir)/model.o \
    $(obj_dir)/time.o \
    $(obj_dir)/findiff.o  \
    $(obj_dir)/findiff2d.o \
    $(obj_dir)/stencils.o \
    $(obj_dir)/stencils2d.o \
    $(obj_dir)/misc.o \
    $(obj_dir)/plt.o \
    $(obj_dir)/blkdat.o \
    $(obj_dir)/nopltlib.o

nfd: fd
fd: $(objects)
    $(fortran_compiler) -o test $(objects)
    mv test $(prog_dir)

# Rule for generating the .o file by compiling the .f file using the fortran compiler
%.o: %.f $(includes)
    $(fortran_compiler) $(fortran_compiler_opts) $(sources)

Contents of sources is

Code:
tree sources/
sources/
├── library
│   ├── fd
│   │   ├── blkdat.f
│   │   ├── findiff2d.f
│   │   ├── findiff.f
│   │   ├── include
│   │   │   ├── fd.com
│   │   │   └── fd.par
│   │   ├── misc.f
│   │   ├── model.f
│   │   ├── plt.f
│   │   ├── stencils2d.f
│   │   ├── stencils.f
│   │   └── time.f
│   └── pltlib
│       ├── colors
│       ├── nopltlib.f
│       ├── pltsub.f
│       ├── xbuplot.c
│       ├── xbuplot_icon
│       └── xpltlib.f
└── programs
    ├── fd.f
    ├── ray.f
    └── zslice.f

Contents of BUILD_DIR is

Code:
tree BUILD_DIR
BUILD_DIR
├── bin
└── obj

---------- Post updated at 02:32 PM ---------- Previous update was at 01:29 PM ----------

---------- Post updated at 04:57 PM ---------- Previous update was at 02:32 PM ----------

I can now compile. However the object file ase created in the local directory rather than sent to ./BUILD_DIR/obj

Code:
# Source code paths

PRGDIR = ./sources/programs
FDLIBDIR = ./sources/library/fd
PLOTLIBDIR = ./sources/library/pltlib

INCDIR = ./sources/library/fd/include/
OBJDIR = ./BUILD_DIR/obj
BINDIR = ./BUILD_DIR/bin

# Set Fortran compiler
fortran_compiler = gfortran

# Set Fortran compiler options
compile_opts = -O -Wall -fbacktrace -fno-align-commons -I./sources/library/fd/include

# Set Fortran compiler options
linking_opts = -O -Wall -fbacktrace -fno-align-commons -I./sources/library/fd/include

# Source files

FDPRG_SRC = $(PRGDIR)/fd.f

FDLIB_SRC = $(FDLIBDIR)/model.f \
    $(FDLIBDIR)/time.f \
    $(FDLIBDIR)/findiff.f \
    $(FDLIBDIR)/findiff2d.f \
    $(FDLIBDIR)/stencils.f \
    $(FDLIBDIR)/stencils2d.f \
    $(FDLIBDIR)/misc.f \
    $(FDLIBDIR)/plt.f \
    $(FDLIBDIR)/blkdat.f

PLOTLIB_SRC = $(PLOTLIBDIR)/nopltlib.f

INCLIB_SRC = $(INCDIR)/fd.par \
    $(INCDIR)/fd.com

# Object files

FDPRG_OBJ = $(OBJDIR)/fd.o

FDLIB_OBJ = $(OBJDIR)/model.o \
    $(OBJDIR)/time.o \
    $(OBJDIR)/findiff.o  \
    $(OBJDIR)/findiff2d.o \
    $(OBJDIR)/stencils.o \
    $(OBJDIR)/stencils2d.o \
    $(OBJDIR)/misc.o \
    $(OBJDIR)/plt.o \
    $(OBJDIR)/blkdat.o

PLOTLIB_OBJ = $(OBJDIR)/nopltlib.o

ALL_OBJ = $(FDPRG_OBJ) $(FDLIB_OBJ) $(PLOTLIB_OBJ) 

# Program name
PROG = $(BINDIR)/fdtest

nfd : $(ALL_OBJ) $(INCLIB_SRC)
    $(fortran_compiler) $(linking_opts) $(ALL_OBJ) -o $(PROG)

# Compiling main program
$(FDPRG_OBJ) : $(FDPRG_SRC) $(INCLIB_SRC)
    $(fortran_compiler) $(compile_opts) -c $(FDPRG_SRC)

# Compiling FD Library
$(FDLIB_OBJ) : $(FDLIB_SRC) $(INCLIB_SRC)
    $(fortran_compiler) $(compile_opts) -c $(FDLIB_SRC) 

# Compiling PLOT Library
$(PLOTLIB_OBJ) : $(PLOTLIB_SRC) $(INCLIB_SRC)
    $(fortran_compiler) $(compile_opts) -c $(PLOTLIB_SRC)

# 4  
Old 01-16-2013
Problem fixed. There was a problem on how the dependencies were being declared
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help running a Makefile from within a .sh script?

Hi there! I am a undergraduate student and recently submitted an assignment for my coursework - however there was one function I could not get to work properly before the due date. Although I don't need to complete this work anymore I would still like to in order to know what was going wrong. If... (11 Replies)
Discussion started by: cherryTango
11 Replies

2. Programming

Problem creating a makefile

hello, I'm trying to create a makefile to run multiple c files. I am able to run one c file only with the code I have when I tried to run 2 or more c files I'm not able. here is my code # $Source: /home/hectormasencio/make/Makefile,v $ # $Date: 2012/11/27 11:35:30 $ CC= gcc OBJS= temp.o... (3 Replies)
Discussion started by: Hector M.
3 Replies

3. Emergency UNIX and Linux Support

Problem With Makefile

I had created a Makefile for my project. my project file hierarchy is like this: 1. a source folder with main.c and Makefile in it 2. and a top level Makefile here is the Makefile in src folder all: program program: main.c gcc -o program main.c clean: rm programand here is top... (3 Replies)
Discussion started by: majid.merkava
3 Replies

4. Programming

Problem with Makefile

Hi, Here is my makefile http://pastie.org/1104332. I am trying to compile different .c files and .s files (assembly files) from different sub directories into E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/ then the linker should link all the .o files from the build directory... (1 Reply)
Discussion started by: blade2008
1 Replies

5. Programming

please help me with this big makefile problem

I need to create an executable with these two makefiles(they both have libaries i need(qt and ruby)) i have extconf.rb gui.ui gui_include.h main.cpp ScaleIM_client.rb ui_gui.h i want to combine them all into one executable please!... (2 Replies)
Discussion started by: gjgfuj
2 Replies

6. UNIX for Advanced & Expert Users

Makefile problem - How to run module load in a Makefile

Hi, I'm trying to run the module load command in a Makefile and i'm getting the following error: make: module: command not found Why is this? Is there any way to run this command in a Makefile? NOTE: command - module load msjava/sunjdk/1.5.0 works fine outside of the Makefile (2 Replies)
Discussion started by: hernandinho
2 Replies

7. UNIX for Dummies Questions & Answers

error while running a makefile

any good website to know about makefiles (3 Replies)
Discussion started by: raviravula
3 Replies

8. Programming

Problem with makefile

My make file is CFLAGS = -Wall -g LDFLAGS = -lm CC = g++ all: server client rc4.o: rc4.cpp rc4.h ${CC} ${CFLAGS} -c rc4.cpp server.o: server.cpp rc4.h ${CC} ${CFLAGS} -c .cpp client.o: client.cpp rc4.h ${CC} ${CFLAGS} -c client.cpp server: server.o... (2 Replies)
Discussion started by: neerajgoyal12
2 Replies

9. Programming

Problem with a Makefile

Hi, I am very new with makefile topics , maybe this is a very symple question... I have this code wich compile very good ( I get it from the net), I will call it code A. I have to add it with a program that is all ready in use, (code B) that also compile good. When I put together it doesnt... (7 Replies)
Discussion started by: pmoren
7 Replies

10. UNIX for Advanced & Expert Users

problem with Makefile

Hi, I have a makefile which looks like this ProcessA : commands touch pro1 ProcessB : pro1 commands touch pro2 ProcessC: pro3 commands and after some runs, i wish only pro3 to run and I check that "pro1" and "pro2" are there in the directory, but still, if i give make... (3 Replies)
Discussion started by: sskb
3 Replies
Login or Register to Ask a Question