Two issues in make file, g++, gfortran


 
Thread Tools Search this Thread
Top Forums Programming Two issues in make file, g++, gfortran
# 1  
Old 03-16-2011
Two issues in make file, g++, gfortran

Question 1:

I have a c++ project that I am trying to re-organize. I am trying to subdivide the src directory to move some src files that seldom are changed to a more out of the way location. The project is a c++ application with a fortran function called from the c.

The reorganization went fine, until I got to the fortran src file. I have two fortran complie rules for the src directory.
Code:
# compile src fortran objects with c preprocessor
$(BDIR)/%.o: $(SOURCELOC)/%.FPP  \
             ${SOURCELOC}/COMMON.BLK \
             $(SOURCELOC)/PARAM.DAT \
             $(SOURCELOC)/ATSYMB.DAT
    $(FCOMP) $(FCFLAGS) $(VFLAGS) -c -o $@ $<

# compile src fortran objects with fortran preprocessor
$(BDIR)/%.o: ${SOURCELOC}/%.FOR \
             ${SOURCELOC}/COMMON.BLK \
             ${SOURCELOC}/PARAM.DAT \
             ${SOURCELOC}/ATSYMB.DAT
    $(FCOMP) $(FCFLAGS) $(VFLAGS) -c -o $@ $<

What I tried to do was to add a driectory to ./src, ./src/src_main/ and move some or the fortran src files into that directory. I added a compile rule for the new subdirectory,
Code:
 $(BDIR)/%.o: ${SOURCELOC}/src_main/%.FOR \
             ${SOURCELOC}/src_main/COMMON.BLK \
             ${SOURCELOC}/src_main/PARAM.DAT \
             ${SOURCELOC}/src_main/ATSYMB.DAT
    $(FCOMP) $(FCFLAGS) $(VFLAGS) -c -o $@ $<

I am getting an error that there is no rule to make the fortran objects. This same method worked fine to move some cpp src files to a different sub directory. I am guessing this is an issue with the fortran includes (COMMON etc), but I would have expected the fortran to fail with a compiler error, not the linker to fail because the object never go compiled. Is there some off the wall syntax to this or something?

Question 2:

I have a little logic that tries to determine which fortran is installed.
Code:
HAVEgfortran := $(shell which gfortran)

ifeq "$(HAVEgfortran)" "/usr/bin/gfortran"
  FCOMP = gfortran
endif
ifeq "$(HAVEgfortran)" "/usr/local/bin/gfortran"
  FCOMP = gfortran
else
  FCOMP = g77
endif

Which gfortran returns /usr/bin/gfortran, but I am getting g77 as FCOMP. I must have made an error in the above, but I can't see it.

Suggestions would be greatly appreciated.

LMHmedchem
# 2  
Old 03-17-2011
Hi.

Question 2:

You are testing HAVEgfortran in the second if sequence which will then (re)set FCOMP. I suggest making the first endif an else, and add another endif, say on a file "m2":
Code:
# Thu Mar 17 09:37:00 CDT 2011

HAVEgfortran := $(shell which gfortran)

ifeq "$(HAVEgfortran)" "/usr/bin/gfortran"
  FCOMP = gfortran
else
  ifeq "$(HAVEgfortran)" "/usr/local/bin/gfortran"
    FCOMP = gfortran
  else
    FCOMP = g77
  endif
endif

.PHONY: all

all:
	@echo " FCOMP is " $(FCOMP)

Then:
Code:
% make -f m2
 FCOMP is  gfortran

This User Gave Thanks to drl For This Post:
# 3  
Old 03-17-2011
Thanks, that fixes the second question. I was sure it was something obvious, but I find limited value in staring at code forever when I can't see what's wrong.

Any ideas as to why my Fortran won't compile?

LMHmedchem
# 4  
Old 03-17-2011
What exactly does it do? Are there any errors?
# 5  
Old 03-17-2011
Hi.

There are no TABS in the rules you posted ... cheers, drl
# 6  
Old 03-17-2011
Quote:
Originally Posted by Corona688
What exactly does it do? Are there any errors?
It just says that there is no rule to make the required object.

Quote:
Originally Posted by drl
Hi.
There are no TABS in the rules you posted ... cheers, drl
I checked, and there is definitely a tab there to start the second line. I am not counting the lines with the continue characters. The src file compiles fine when it is in src/, with the same rule, but when I move the src file to src/src_Main/ and add a rule for src/src_Main/, the object doesn't get created.

The cpp files in that folder get compiled, it is just the Fortran that are being skipped.

LMHmedchem
# 7  
Old 03-17-2011
Hi.

Let us step back a minute.
Quote:
Originally Posted by LMHmedchem
... I am getting an error that there is no rule to make the fortran objects. This same method worked fine to move some cpp src files to a different sub directory. I am guessing this is an issue with the fortran includes (COMMON etc), but I would have expected the fortran to fail with a compiler error, not the linker to fail because the object never go compiled ...
If make thinks there is no rule, then the compiler would not get called, and so there could not be an error in compilation. If there is no compilation, then I would expect the linker to complain.

Could you explain more about "same method worked fine to move some cpp src files" -- are you saying that the makefile causes files to be moved? Or that you moved them and that a makefile for cpp worked correctly?

Do you have cpp and fortran source in the same directory, and have a single makefile for both the cpp and fortran codes?

Please post the exact error message that you get -- copy and paste so you get all the characters.

The version of make you are using would also be useful.

cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Make and gmake issues

Hello I am working on a CPP code written for SUN CC 5.5 and make we used make to compile the code then it compilation went smooth now i am using gmake: I have a make file like this WSROOT=.. include $(WSROOT)/etc/wsmkinclude.common all: @for subdir in */Makefile; \ do \... (1 Reply)
Discussion started by: Revathi R
1 Replies

2. Programming

Make and gmake issues

Hello I am working on a CPP code written for SUN CC 5.5 and make we used make to compile the code then it compilation went smooth now i am using gmake: I have a make file like this WSROOT=.. include $(WSROOT)/etc/wsmkinclude.common all: @for subdir in */Makefile; \ do \... (1 Reply)
Discussion started by: Revathi R
1 Replies

3. Programming

gfortran 4.7, no support for qfloat?

I have code that works fine in ifort. But when trying to run on gfortran 4.7.1 (which does support quads and has no problem with real * 16) I can't cast an integer variable to a quad precision float (real*16) using something like: factq(i) = factq(i-1) * qfloat(i) Finding a list of the new... (2 Replies)
Discussion started by: vibrantcascade
2 Replies

4. Programming

Compilation problem with gfortran

Hello everyone, I'm trying since a few days to compile a f90 program with gfortran (on Ubuntu) with a makefile. The fortran program calls 2 routines written in C. Here is my makefile: FC = gfortran SFC = gfortran FFLAGS = -ffree-form -O... (21 Replies)
Discussion started by: leroygr
21 Replies

5. Programming

Gfortran compiler options.

I am a INTEL fortran user recently migrated to linux and installed gfortran on my system. I run numerical models as part of my research. my question is on optimization of the fortran code. I used the - vectorize option to compile for reducing the run time considerably and was happy. But... (1 Reply)
Discussion started by: schamarthi1
1 Replies

6. Programming

f77 program on gfortran

Hi, I am trying to run a simple f77 program on gfortran. Program is as follows. program trial implicit real*8 (a-h,o-z) common/var/a(2),b,c(4),d a=(/0,0/) b=0 c=(/0,0,0,0/) d=0 call add(a,b,c,d) ... (1 Reply)
Discussion started by: anshulfy
1 Replies

7. Programming

gfortran not connecting to system libraries

Hi ! I have one program made of several sub programs which I am trying to compile with gfortran on Fedora 14 in my system. The program was originally written in Fortran 77 and compilation command used to be - fort77 -O2 -f -w -o life life_com.f lifetime.f minuit.f tek_life.f utilities.f... (0 Replies)
Discussion started by: cylab123
0 Replies

8. Programming

Fortran 77 and gfortran

Hi! I have a program in fortran77. This program was compiled with pgf90, but now, I need compiled it with gfortran. I show a bit of code. program hello PARAMETER(a=100) integer a write(*,*)'value ', a end program hello What's the problem? Thanks (2 Replies)
Discussion started by: kekaes
2 Replies

9. Programming

makeutility: how to get the make-file name inside of the make-file?

How I can get the current make-file name in a make-file So, if I run make with specified file:make -f target.mak is it possible to have the 'target' inside of the that 'target.mak' from the file name? (2 Replies)
Discussion started by: alex_5161
2 Replies

10. Red Hat

AMBER md/g95/gfortran issue

Hi, i am trying to install AMBER10 which is a molecular dynamcis package onto two linux red hat pcs. I can successfully install the tools that comes with which uses gcc to compile, however AMBER10 requires either g95 or gfortran to compile. This is where the issue lies, i have installed both... (0 Replies)
Discussion started by: olifu02
0 Replies
Login or Register to Ask a Question