Incompatibility with GCC 6.x

Submitted by yunhailiseu on Thu, 05/18/2017 - 19:50

Forums 

Installation

Dear Developers,

Recently I tried to build BGW-1.2.0 on Fedora 25 with GCC 6.x. However, gfortran kept complaining about source code format error and the compilation never succeed. After some investigation and tests I found that it was due to a possible incompatibility of GCC 6.x, which I will describe briefly below.

When using cpp for FORTRAN source code, the '-C' option is required to retain the all comments. For GCC 6.x, using 'cpp -C' inserts additional copyright notice of Glibc in the processed source code. The copyright notice is in C-style comment (/**/) and causes gfortran to abort. However, no such copyright notice is included for GCC 4.x.

As a workaround, I wrote a python program to remove the C-style comments in the processed source file (*.p.f) and modified Common/common-rules.mk accordingly. Although this workaround works, I think expert advice is needed.

Best,
Yunhai Li

Submitted by nicholascheng on Sun, 09/24/2017 - 23:36

Hello,

I am also facing the same issue - I'm not able to build BGW-1.2.0 on Ubuntu 17.04. But I don't know how to do the workaround. May I know how to get rid of the appended comments? Thank you.

Warmest regards,
Nicholas

Submitted by yunhailiseu on Mon, 09/25/2017 - 01:07

1. Modify these lines in Common/common-rules.mk. Changes are highlighted in bold text.

ifeq ($(findstring clang,$(FCPP)),clang)
f90_CPP = cp $(basename $<).f90 $(basename $<)_cp.F90; $(FCPP) $(INCLUDE) $(CPPOPT) $(basename $<)_cp.F90 > $(basename $<).p.f; $(REMOVE) $(basename $<)_cp.F90
else
f90_CPP = $(FCPP) $(INCLUDE) $(CPPOPT) $< > $(basename $<).p.f; $(PREFIX)/rmcmt.py $(basename $<).p.f
endif
F90_CPP = $(FCPP) -P $(INCLUDE) $(CPPOPT) $< > $(basename $<).p.f; $(PREFIX)/rmcmt.py $(basename $<).p.f

2. Create a python script named rmcmt.py, paste these lines into it, and "chmod 755 rmcmt.py". Note that python is indent-sensitive. The indents are dropped in this post. You have to add them manually.

#! /usr/bin/env python
import sys
fnm = sys.argv[1]
infile = open(fnm, "r")
content = infile.readlines()
infile.close()
ofile = open(fnm, "w")
iscomm = False
for line in content:
# if this is a single-line comment (/*xxx*/), do nothing
if line.find("/*") != -1 and line.find("*/") != -1:
continue
# if this is a starting line, set iscomm = True
elif line.find("/*") != -1 and line.find("*/") == -1:
iscomm = True
# if this is an ending line, set iscomm = False
elif line.find("/*") == -1 and line.find("*/") != -1:
iscomm = False
# for other lines, use iscomm to determine whether to write this line to file
else:
if not iscomm:
ofile.write(line)
ofile.close()

3. Follow the ordinary compilation procedure. Good luck!

Best,
Yunhai Li

Submitted by nicholascheng on Mon, 09/25/2017 - 18:27

Thank you so much! The compilation is successful. Proceeding to test the build.

Warmest regards,
Nicholas