gpt4 book ai didi

makefile - cpp 预处理器为 Fortran 编译器添加不需要的文本

转载 作者:行者123 更新时间:2023-12-01 01:05:01 27 4
gpt4 key购买 nike

我相信我的 Makefile(编译 Fortran 代码)使用的 cpp 预处理器有问题。我最近更换了操作系统,现在编译不起作用,我对 Makefile 或预处理器的了解不够,无法修复它(Makefile 是多年前给我的)。

我最近从 Fedora 10 更新到 Fedora 19(是的,应该更早更新)。将我的代码复制到新系统并运行 gmake 后,我发现我在编译时遇到了问题。据我所知,应该发生的是我的 .F 文件被预处理并写入 .f 文件。显然,cpp 预处理器现在正在添加某种 GNU 免责声明(“/* Copyright (C) 1991-2012 Free Software Foundation, Inc. 该文件是 GNU C 库的一部分......”),编译器 ( f77) 不喜欢。原则上,我可以从每个生成的 .f 文件中删除此文本,但严重的是,这需要太多时间。

我真的不知道问题的原因是什么。我想告诉 cpp 不要输出这个文本,或者 f77 忽略它,但没有找到任何管理这个的标志。考虑过重新编写 Makefile(例如,使用更现代的编译器),但目前我对此感到有点绝望。希望有人能帮我解决这个问题。我正在复制下面的 Makefile 以及输出。

提前致谢。

生成文件

# Make sure the SHELL is right
SHELL = /bin/sh
MAKE = gmake

# Define several root directories
LEP_ROOT := /home/stilgar/SUSY/NeutrinoModel2
CERN_ROOT := /usr/lib64/cernlib/2006
INCLUDES := $(LEP_ROOT)/include
INCLUDES := $(strip $(INCLUDES))
incpath := $(subst $(space),:,$(INCLUDES))

vpath %.inc $(incpath)

# Define tree
BIN_DIR := $(LEP_ROOT)/bin

# Define source directory
SRCDIR := $(LEP_ROOT)/src

# Libraries
libs := $(CERN_ROOT)/lib
libs := $(addprefix -L, $(libs))
libs += `cernlib packlib,mathlib,packlib,kernlib`

#Source files
#Main Program
src_files += $(wildcard $(SRCDIR)/main_lfv.F)
#SM Parameters
src_files += $(wildcard $(SRCDIR)/param_basic.F)
src_files += $(wildcard $(SRCDIR)/numajmass.F)
#SUSY Spectrum
src_files += $(wildcard $(SRCDIR)/texture2.F)
src_files += $(wildcard $(SRCDIR)/minserts.F)
#SUSY Flavour
src_files += $(wildcard $(SRCDIR)/gmin2.F)
src_files += $(wildcard $(SRCDIR)/lfv.F)
#Bounds
src_files += $(wildcard $(SRCDIR)/experiment.F)
src_files += $(wildcard $(SRCDIR)/directsearch.F)
#Loop Functions
src_files += $(wildcard $(SRCDIR)/fedm.F)
src_files += $(wildcard $(SRCDIR)/gedm.F)
#Mathematical Tools
src_files += $(wildcard $(SRCDIR)/biunitary3.F)

main_obj_files += $(src_files:%.F=%.o)
main_ofiles += $(notdir $(main_obj_files))
main_files += $(src_files:%.F=%.f)
depend += $(main_obj_files:.o=.d)

# Name of the executable to be created
exectry := $(BIN_DIR)/RunStuff

# Define flags
FC = f77
#FC = gfortran
#FC = g95
FFLAGS += -c
FFLAGS += $(addprefix -I, $(INCLUDES))

# Define cpp options
CPP = cpp
CPPFLAGS += -C -P -E
CPPFLAGS += $(addprefix -I, $(INCLUDES))

.PHONY : all clean cleanall help
.PHONY : sclean

all: $(exectry)

$(exectry): $(main_obj_files) $(main_files)
@echo '==================================================='
@echo ' Building executable ' $(exectry)
@echo ' '
@-rm -f $@
$(FC) -o $@ $(main_obj_files) $(LFLAGS) $(libs)
@echo ' Done '
@echo '==================================================='

clean : sclean
@echo
@echo Cleaning up *.o *~ core
@echo
@-rm -f *.o core
@echo done.
sclean :
@find . -name "*.bak" -exec rm -f '{}' ';'
@find . -name "*~" -exec rm -f '{}' ';'
@find . -name "#*#" -exec rm -f '{}' ';'

cleanall :
@echo '**********************************************************'
@echo ' Clean all : '
@find . -name "*.bak" -exec rm -f '{}' ';'
@find . -name "*~" -exec rm -f '{}' ';'
@find . -name "*.log" -exec rm -f '{}' ';'
@find . -name "*.out" -exec rm -f '{}' ';'
@find . -name "core" -exec rm -f '{}' ';'
@find . -name "#*#" -exec rm -f '{}' ';'
@-rm -f *.o *.d
@echo done.
@echo '**********************************************************'
help:
@echo
@echo ' The possible options are :'
@echo ' ======================== '
@echo
@echo ' gmake -- build batch executable'
@echo ' gmake sclean -- simple clean up '
@echo ' gmake clean -- clean up a bit more '
@echo ' gmake cleanall -- clean everything'
@echo

%.f:%.F
@echo Preprocessing ... $<
@$(CPP) $(CPPFLAGS) $< > $@

%.o:%.f
@echo Compiling ... $<
@$(FC) $(FFLAGS) -o $@ $<

%.d:%.F
@touch $@
@echo Updating ... $@
@makedepend -- $(CPPFLAGS) -- $< -f $@
@-rm $@.bak

输出
 Preprocessing ... /home/stilgar/SUSY/NeutrinoModel2/src/main_lfv.F
Compiling ... /home/stilgar/SUSY/NeutrinoModel2/src/main_lfv.f
/home/stilgar/SUSY/NeutrinoModel2/src/main_lfv.f:2:
This file is part of the GNU C Library.
^
Non-numeric character at (^) in label field [info -f g77 M LEX]
/home/stilgar/SUSY/NeutrinoModel2/src/main_lfv.f:4:
The GNU C Library is free software; you can redistribute it and/or
^
Non-numeric character at (^) in label field [info -f g77 M LEX]
/home/stilgar/SUSY/NeutrinoModel2/src/main_lfv.f:5:
modify it under the terms of the GNU Lesser General Public
^
Non-numeric character at (^) in label field [info -f g77 M LEX]

(...)

gmake: *** [/home/stilgar/SUSY/NeutrinoModel2/src/main_lfv.o] Error 1

最佳答案

我认为问题是-C CPPFLAGS 中的选项多变的。 cpp 的手册页说这会导致预处理器不丢弃注释。我不认为你想要那个。去掉那个标志。

另一个 nit:你永远不想设置 MAKE生成文件中的变量。

关于makefile - cpp 预处理器为 Fortran 编译器添加不需要的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19571881/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com