0

Mac OS X lionを最新のXcode(4.3)で実行しています。

gfortran --version # -> GNU Fortran (GCC) 4.6.1
gcc --version # -> i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658)

私のmakefileはエラーを出します:

gfortran temp/modules.o temp/testModules.o temp/mathFunctions.o temp/functionTest.o -o arenatest
ld: duplicate symbol ___rng_MOD_uni in temp/testModules.o and temp/modules.o for architecture x86_64
collect2: ld returned 1 exit status
make: *** [arenatest] Error 1

理由がわからないので、同じことをするビルドスクリプトを書いてみましたが、意外と動作します。スクリプトではなくメイクファイルが欲しいので、誰かが違いを見つけることができますか?私は完全にアイデアがありません。

正しいサブディレクトリに.oオブジェクトを生成するためのファンキーなループ置換スクリプトがあることを私は知っています。ただし、build/compile-コマンドは完全に一致しているようです。これを行うための賢い方法があれば、私は提案を受け付けています。

脚本:

echo remove old files
rm *.mod
rm *.o
rm -rf temp
rm arenatest

echo create directories and compile:
mkdir -p temp
gfortran -cpp -c ../modules/modules.f90 -o temp/modules.o -J../buildtest -I../buildtest
gfortran -cpp -c ../modules/mathFunctions.f90 -o temp/mathFunctions.o -J../buildtest -I../buildtest
gfortran -cpp -c testModules.f90 -o temp/testModules.o -J../buildtest -I../buildtest
gfortran -cpp -c functionTest.f90 -o temp/functionTest.o -J../buildtest -I../buildtest

echo do linking: gfortran -cpp temp/modules.o temp/testModules.o temp/mathFunctions.o temp/functionTest.o -o arenatest
gfortran temp/modules.o temp/testModules.o temp/mathFunctions.o temp/functionTest.o -o arenatest

echo DONE!

makefile:

PROGRAM = arenatest
BUILDDIR = temp
FC = gfortran
SRC = ../modules/modules.f90 ../modules/mathFunctions.f90 testModules.f90 functionTest.f90
OBJ = $(SRC:.f90=.o)
OBJECTS = $(foreach var, $(OBJ), $(BUILDDIR)/$(lastword $(subst /, , $(var))) )
FLAGS =-J../buildtest -I../buildtest


all: buildtest

buildtest: $(PROGRAM)

build_message:
    @echo
    @echo sources:
    @echo $(SRC)
    @echo objects:
    @echo $(OBJECTS)

clean:
    rm -rf temp
    rm arenatest
    rm *.mod
    rm *.o


mkdir:
    @echo create directories and compile:
    mkdir -p temp

# 
# gfortran -cpp -c ../modules/modules.f90 -o temp/modules.o -J../buildtest -I../buildtest
# gfortran -cpp -c ../modules/mathFunctions.f90 -o temp/mathFunctions.o -J../buildtest -I../buildtest
# gfortran -cpp -c testModules.f90 -o temp/testModules.o -J../buildtest -I../buildtest
# gfortran -cpp -c functionTest.f90 -o temp/functionTest.o -J../buildtest -I../buildtest
# 
$(OBJECTS) : $(SRC) | mkdir
    $(FC) -c $(FLAGS) $< -o $@
# link: #echo do linking: gfortran -cpp temp/modules.o temp/testModules.o temp/mathFunctions.o temp/functionTest.o -o arenatest
$(PROGRAM): $(OBJECTS) | build_message
    $(FC) $(FLAGS) $(OBJECTS) -o $(PROGRAM)

#echo DONE!
4

1 に答える 1

0

オブジェクトファイルをコンパイルするためのレシピが間違っています。変数を展開すると、次のようになります。

temp/modules.o temp/mathFunctions.o temp/testModules.o temp/functionTest.o: ../modules/modules.f90 ../modules/mathFunctions.f90 testModules.f90 functionTest.f90 | mkdir
    $(FC) -c $(FLAGS) $< -o $@

事実上、これは各オブジェクトファイルがすべてのソースファイルに依存していることを意味します。さらに、このレシピを呼び出すたびに、自動変数$<がこのソースファイルのリストの最初の変数に設定されます。これにより、すべてのオブジェクトファイルが同じ単一のソースファイルからコンパイルされることになります(したがって、もちろんすべてに同じシンボルの定義があります)。

于 2012-03-07T12:29:46.973 に答える