我正在尝试构建一个非常简单的Makefile,它打算使用由Fortran模块制成的自制库(libf904QC.a
)。 库在/usr/local/lib64
,而相应的.mod
文件在/usr/local/include/f904QC
这是生成文件
# Makefile
NAME=NPManip
FFLAGS= -ffpe-trap=overflow -c -O3
LFLAGS=
PATH2LIB=/usr/local/lib64/
INCLUDEDIR=/usr/local/include/f904QC/
#
LIB=-L$(PATH2LIB) -I$(INCLUDEDIR) -lf904QC.a
OBJS =
tools_NPManip.o
NPManip.o
%.o: %.f90
gfortran $(LIB) $(FFLAGS) $*.f90
NPM: $(OBJS)
gfortran $(LFLAGS) $(OBJS) $(LIB) -o $(NAME)
clean:
@if test -e $$HOME/bin/$(NAME); then
rm $$HOME/bin/$(NAME);
fi
rm *.o *.mod
mrproper: clean
rm $(NAME)
install:
ln -s $(shell pwd)/$(NAME) $$HOME/bin/.
我收到以下错误消息:
gfortran tools_NPManip.o NPManip.o -L/usr/local/lib64/-I/usr/local/include/f904QC/-lf904QC.a -o NPManip
/usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../x86_64-suse-linux/bin/ld: 找不到 -lf904QC.a
collect2:错误:ld 返回 1 个退出状态
制造: * [NPM] 错误 1
错误在哪里?这对我来说并不明显,因为libf904QC.o
实际上位于 /usr/local/lib64
中,由 -L
选项定义。
感谢您的帮助
您应该指定库的完整路径/usr/local/lib64/libf904QC.a
或 -L/usr/local/lib64 -lf90QC
,在这种情况下不带.a
。从 man ld
:
-l namespec
--library=namespec
Add the archive or object file specified by namespec to the list of files to link. This option may be used any number of
times. If namespec is of the form :filename, ld will search the library path for a file called filename, otherwise it
will search the library path for a file called libnamespec.a.
-L searchdir
--library-path=searchdir
Add path searchdir to the list of paths that ld will search for archive libraries and ld control scripts. You may use
this option any number of times. The directories are searched in the order in which they are specified on the command
line. Directories specified on the command line are searched before the default directories. All -L options apply to
all -l options, regardless of the order in which the options appear. -L options do not affect how ld searches for a
linker script unless -T option is specified.