【问题标题】:Error in including homemade Fortran modules and libraries in Makefile在 Makefile 中包含自制 Fortran 模块和库时出错
【发布时间】:2013-11-29 10:59:37
【问题描述】:

我正在尝试构建一个非常简单的 Makefile,它打算使用由 Fortran 模块制成的自制库 (libf904QC.a)。该库位于/usr/local/lib64,而相应的.mod 文件位于/usr/local/include/f904QC

这是 Makefile

# 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 个退出状态

make: * [NPM] Erreur 1

错在哪里?这对我来说并不明显,因为libf904QC.o 实际上位于/usr/local/lib64,这是由-L 选项定义的。

感谢您的帮助

【问题讨论】:

  • 您是在尝试链接对象libf904QC.o 还是归档libf904QC.a?尝试将-lf904QC.a 替换为目标文件的完整路径。

标签: module makefile fortran libraries


【解决方案1】:

您应该指定库的完整路径/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.

【讨论】:

  • 谢谢!我已经指定了-L/usr/local/lib64 -lf90QC,它当然可以正常工作。现在看起来很明显,但不是昨天。这就像埃德加·坡被盗的信。解决方案就在你眼前,但你却看不见……
猜你喜欢
  • 1970-01-01
  • 2018-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-21
  • 1970-01-01
相关资源
最近更新 更多