`make check` 在 VPATH 中失败

Posted

技术标签:

【中文标题】`make check` 在 VPATH 中失败【英文标题】:`make check` fails in VPATH 【发布时间】:2014-08-25 17:41:13 【问题描述】:

我正在尝试使用 libtool 目标和测试创建一个基于 autotools 的项目。

除了 VPATH 中的 make check(或 make distcheck)之外,一切都有效。

这是用于测试的Makefile.am

AM_CPPFLAGS = -I$(top_srcdir)/include
LDADD = $(top_srcdir)/lib/libboilerplate.la

check_PROGRAMS = test test_fail
test_SOURCES = test.c
test_fail_SOURCES = test_fail.c

TESTS = $(check_PROGRAMS)
XFAIL_TESTS = test_fail

这是make check 的输出:

Making check in include
make[1]: Nothing to be done for `check'.
Making check in lib
/bin/sh ../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT boilerplate.lo -MD -MP -MF .deps/boilerplate.Tpo -c -o boilerplate.lo boilerplate.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT boilerplate.lo -MD -MP -MF .deps/boilerplate.Tpo -c boilerplate.c  -fno-common -DPIC -o .libs/boilerplate.o
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT boilerplate.lo -MD -MP -MF .deps/boilerplate.Tpo -c boilerplate.c -o boilerplate.o >/dev/null 2>&1
mv -f .deps/boilerplate.Tpo .deps/boilerplate.Plo
/bin/sh ../libtool  --tag=CC   --mode=link gcc  -g -O2   -o libboilerplate.la -rpath /usr/local/lib boilerplate.lo  
libtool: link: gcc -dynamiclib -Wl,-undefined -Wl,dynamic_lookup -o .libs/libboilerplate.0.dylib  .libs/boilerplate.o    -O2   -install_name  /usr/local/lib/libboilerplate.0.dylib -compatibility_version 1 -current_version 1.0 -Wl,-single_module
libtool: link: (cd ".libs" && rm -f "libboilerplate.dylib" && ln -s "libboilerplate.0.dylib" "libboilerplate.dylib")
libtool: link: ar cru .libs/libboilerplate.a  boilerplate.o
libtool: link: ranlib .libs/libboilerplate.a
libtool: link: ( cd ".libs" && rm -f "libboilerplate.la" && ln -s "../libboilerplate.la" "libboilerplate.la" )
Making check in src
gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
mv -f .deps/main.Tpo .deps/main.Po
/bin/sh ../libtool  --tag=CC   --mode=link gcc  -g -O2   -o boilerplate main.o  
libtool: link: gcc -g -O2 -o boilerplate main.o 
Making check in tests
/Applications/Xcode.app/Contents/Developer/usr/bin/make  test test_fail
gcc -DHAVE_CONFIG_H -I. -I..  -I../include   -g -O2 -MT test.o -MD -MP -MF .deps/test.Tpo -c -o test.o test.c
mv -f .deps/test.Tpo .deps/test.Po
/bin/sh ../libtool  --tag=CC   --mode=link gcc  -g -O2   -o test test.o ../lib/libboilerplate.la 
libtool: link: gcc -g -O2 -o .libs/test test.o  ../lib/.libs/libboilerplate.dylib
gcc -DHAVE_CONFIG_H -I. -I..  -I../include   -g -O2 -MT test_fail.o -MD -MP -MF .deps/test_fail.Tpo -c -o test_fail.o test_fail.c
mv -f .deps/test_fail.Tpo .deps/test_fail.Po
/bin/sh ../libtool  --tag=CC   --mode=link gcc  -g -O2   -o test_fail test_fail.o ../lib/libboilerplate.la 
libtool: link: gcc -g -O2 -o .libs/test_fail test_fail.o  ../lib/.libs/libboilerplate.dylib
/Applications/Xcode.app/Contents/Developer/usr/bin/make  check-TESTS
PASS: test
XFAIL: test_fail
make[4]: Nothing to be done for `all'.
============================================================================
Testsuite summary for boilerplate 1.0
============================================================================
# TOTAL: 2
# PASS:  1
# SKIP:  0
# XFAIL: 1
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================

VPATH 中make check 的输出:

Making check in include
make[1]: Nothing to be done for `check'.
Making check in lib
/bin/sh ../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../lib -I..     -g -O2 -MT boilerplate.lo -MD -MP -MF .deps/boilerplate.Tpo -c -o boilerplate.lo ../../lib/boilerplate.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../lib -I.. -g -O2 -MT boilerplate.lo -MD -MP -MF .deps/boilerplate.Tpo -c ../../lib/boilerplate.c  -fno-common -DPIC -o .libs/boilerplate.o
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../lib -I.. -g -O2 -MT boilerplate.lo -MD -MP -MF .deps/boilerplate.Tpo -c ../../lib/boilerplate.c -o boilerplate.o >/dev/null 2>&1
mv -f .deps/boilerplate.Tpo .deps/boilerplate.Plo
/bin/sh ../libtool  --tag=CC   --mode=link gcc  -g -O2   -o libboilerplate.la -rpath /usr/local/lib boilerplate.lo  
libtool: link: gcc -dynamiclib -Wl,-undefined -Wl,dynamic_lookup -o .libs/libboilerplate.0.dylib  .libs/boilerplate.o    -O2   -install_name  /usr/local/lib/libboilerplate.0.dylib -compatibility_version 1 -current_version 1.0 -Wl,-single_module
libtool: link: (cd ".libs" && rm -f "libboilerplate.dylib" && ln -s "libboilerplate.0.dylib" "libboilerplate.dylib")
libtool: link: ar cru .libs/libboilerplate.a  boilerplate.o
libtool: link: ranlib .libs/libboilerplate.a
libtool: link: ( cd ".libs" && rm -f "libboilerplate.la" && ln -s "../libboilerplate.la" "libboilerplate.la" )
Making check in src
gcc -DHAVE_CONFIG_H -I. -I../../src -I..     -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o ../../src/main.c
mv -f .deps/main.Tpo .deps/main.Po
/bin/sh ../libtool  --tag=CC   --mode=link gcc  -g -O2   -o boilerplate main.o  
libtool: link: gcc -g -O2 -o boilerplate main.o 
Making check in tests
/Applications/Xcode.app/Contents/Developer/usr/bin/make  test test_fail
gcc -DHAVE_CONFIG_H -I. -I../../tests -I..  -I../../include   -g -O2 -MT test.o -MD -MP -MF .deps/test.Tpo -c -o test.o ../../tests/test.c
mv -f .deps/test.Tpo .deps/test.Po
make[2]: *** No rule to make target `../../lib/libboilerplate.la', needed by `test'.  Stop.
make[1]: *** [check-am] Error 2
make: *** [check-recursive] Error 1

有人知道为什么会这样吗?

【问题讨论】:

【参考方案1】:

你写道:

LDADD = $(top_srcdir)/lib/libboilerplate.la

但是,这会将输出文件放入源代码树中——这是错误的。请改用$(top_builddir)

【讨论】:

谢谢!我曾尝试使用$(top_builddir),但我也更改了AM_CPPFLAGS 中的包含路径,导致包含错误。但是当然,包含路径取决于源,链接路径取决于构建。

以上是关于`make check` 在 VPATH 中失败的主要内容,如果未能解决你的问题,请参考以下文章

第18课 - make 中的路径搜索(下)

make ffmpeg makefile

7.Makefile目标文件搜索(VPATH和vpath)

7.Makefile目标文件搜索(VPATH和vpath)

Linux C基础——” Makefile “ 文件管理大师你拜访过嘛?

18.make中的路径搜索(下)