如果我们在测试代码中有多个 *.c 文件,有人知道如何编写 Check makefile.am 吗?例子:
#include "../src/SpeedGauge.h"
#include "../src/CruiseManager.h"
#include "../src/Throttle.h"
SpeedGauge speedo;
CruiseManager controller;
Throttle throttle;
/* Test case for - Case1 */
START_TEST (test_Case1)
{
int expected = 11; // TODO: Initialize to an appropriate value
speedo.time = 1111; // TODO: Initialize to an appropriate value
speedo.rotaryCount = 3333; // TODO: Initialize to an appropriate value
// tick: 1
SpeedGauge_calcSpeed(&speedo);
CruiseManager_set(&controller);
Throttle_normal(&throttle);
int result = throttle.throttleVal;
fail_unless (result == expected, "Expecting <%i> instead of <%i>", expected, result);
}
END_TEST
这是我的makefile.am:
## Process this file with automake to produce Makefile.in
lib_LTLIBRARIES = libSpeedGauge.la libCruiseManager.la libThrottle.la
libSpeedGauge_la_SOURCES = SpeedGauge.c SpeedGauge.h CruiseManager.c CruiseManager.h Throttle.c Throttle.h
bin_PROGRAMS = main
main_SOURCES = main.c
main_LDADD = libSpeedGauge.la libCruiseManager.la libThrottle.la
我收到一个错误说:
libtool: link: ranlib .libs/libSpeedGauge.a
libtool: link: ( cd ".libs" && rm -f "libSpeedGauge.la" && ln -s "../libSpeedGauge.la" "libSpeedGauge.la" )
make[2]: *** No rule to make target `libCruiseManager.lo', needed by `libCruiseManager.la'. Stop.
make[2]: Leaving directory `/home/mjaa001/Desktop/cruisecontrol/src'
make[1]: *** [all-recursive] Error 1
它似乎无法链接编译代码。我是否错误地指定了 lib 类,或者我只需要一个类文件?
更新
通过编辑 makefile.am 来解决
libSpeedGauge_la_SOURCES = SpeedGauge.c SpeedGauge.h CruiseManager.c CruiseManager.h Throttle.c Throttle.h
至
libSpeedGauge_la_SOURCES = SpeedGauge.c SpeedGauge.h
libCruiseManager_la_SOURCES = CruiseManager.c CruiseManager.h
libThrottle_la_SOURCES = Throttle.c Throttle.h