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!