CSDN的同学们好,在按照autotools一书进行学习时,有遇到make不按照VPATH设定的目录进行搜索的情况,将情况简述如下:
1、目录树如下所示:
.
├── autom4te.cache
│ ├── output.0
│ ├── output.1
│ ├── requests
│ ├── traces.0
│ └── traces.1
├── build
│ ├── config.log
│ ├── config.status
│ ├── jupiter-1.0.tar.gz
│ ├── Makefile
│ └── src
│ └── Makefile
├── configure
├── configure.ac
├── Makefile.in
└── src
├── main.c
└── Makefile.in
4 directories, 15 files
2、在build目录下面进行相应的操作,build/src/Makefile文件的内容为:
# src/Makefile. Generated from Makefile.in by configure.
# Package-specific substitution variables
package = Jupiter
version = 1.0
tarname = jupiter
distdir = $(tarname)-$(version)
# Prefix-specific substitution variables
prefix = /usr/local
exec_prefix = ${prefix}
bindir = ${exec_prefix}/bin
# VPATH-related substitution variables
srcdir = ../../src
VPATH = ../../src
CFLAGS = -g -O0
all: jupiter
jupiter: main.c
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ main.c
clean:
-rm jupiter
check: all
./jupiter | grep "Hello from .*jupiter!"
@echo "*** ALL TESTS PASSED ***"
install:
install -d $(DESTDIR)$(bindir)
install -m 0755 jupiter $(DESTDIR)$(bindir)
uninstall:
-rm $(DESTDIR)$(bindir)/jupiter
Makefile: Makefile.in ../config.status
cd .. && ./config.status src/$@
../config.status: ../configure
cd .. && ./config.status --recheck
.PHONY: all clean check install uninstall
3、如2所示编译main.c的命令为:
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ main.c
VPATH被赋值为: ../../src
真正的main.c文 件是../../src/main.c按照VPATH的设置应该是可以找到main.c的,但我在make jupiter的时候,却遇到了错误输出,输出的信息为:
cd src && make jupiter
make[1]: 正在进入目录 `/home/BTN/BTN/autotools/jupiter/build/src'
cc -g -O0 -o jupiter main.c
cc: error: main.c: 没有那个文件或目录
cc: fatal error: no input files
compilation terminated.
make[1]: *** [jupiter] 错误 4
make[1]:正在离开目录 `/home/BTN/BTN/autotools/jupiter/build/src'
make: *** [jupiter] 错误 2
4 请教一下大家,这个问题是什么原固导致的,又要怎样解决?谢谢。
20150128143800:
我后来,在网络上面搜索,没有看到直接关于这个问题的描述,但有一个类似的,在一个博客中看到有说他依懒的一个文件说没有找到,将依懒的文件换成$<就可以了,他的理解是make有对$<展开,而没有对直接写出来文件名的进行扩展,所以我的修改是:
将 $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ main.c换为:
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^
成功。
Hello John Calcote:
You can call me BTNZ, I'm Chinese. My English is not good, I have to rely on a translator to communicate with you. I follow the example of your book which title is "AutoTools A Practitioner's Guide to GNU Autoconf, Automake, and Libtool". At page of 70 I got a problem it's about VPATH, I added srcdir = @srcdir@ and VPATH = @srcdir@ into jupiter/src/Makefile.in then executive ../configure in the "build" directory, it generate several file and directory under "build" directory, I typed "make jupiter" and Enter but the output information of the terminal is:
BTN@BT:~/BTN/autotools/jupiter/build$ make jupiter
cd src && make jupiter
make[1]: 正在进入目录 `/home/BTN/BTN/autotools/jupiter/build/src'
cc -g -O0 -o jupiter main.c
cc: error: main.c: 没有那个文件或目录
cc: fatal error: no input files
compilation terminated.
make[1]: *** [jupiter] 错误 4
make[1]:正在离开目录 `/home/BTN/BTN/autotools/jupiter/build/src'
make: *** [jupiter] 错误 2
BTN@BT:~/BTN/autotools/jupiter/build$
I checked jupiter/build/src/Makefile check the command of "make jupiter" it is: $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ main.c, I search on the web and find the right solution, it is: $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^
I send this email to let you know how this thing.
Thank you.