2013-11-15 3 views
1

Я пытаюсь создать очень простой Makefile, который намеревается использовать домашнюю библиотеку (libf904QC.a) из модулей Fortran. Библиотека находится в /usr/local/lib64 в то время как соответствующие .mod файлы в /usr/local/include/f904QCОшибка в использовании самодельных модулей и библиотек Fortran в Makefile

Вот 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: cannot find -lf904QC.a

collect2: error: ld returned 1 exit status

make: * [NPM] Erreur 1

Где ошибка? Для меня это не очевидно, так как libf904QC.o фактически находится в /usr/local/lib64, что определяется опцией -L.

Thnak Вас за помощь

+0

Вы пытаетесь связать с объектом 'libf904QC.o' или архив' libf904QC.a'? Попробуйте заменить '-lf904QC.a' полный путь к объекту. – milancurcic

ответ

2

Вы должны указать либо полный путь к библиотеке /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. 
+0

Спасибо! Я указал -L/usr/local/lib64 -lf90QC, и он отлично работает, конечно. Сейчас это кажется очевидным, но это было не вчера. Это похоже на проклятое письмо Эдгара По. Решение находится у вас на глазах, но вы не можете его увидеть ... – user2997973

Смежные вопросы