如何使用multipe源文件和标题编写检查测试makefile.am?

时间:2011-02-14 22:21:01

标签: c unit-testing check-framework

如果我们在测试代码中有超过* .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

2 个答案:

答案 0 :(得分:3)

lib_LTLIBRARIES = libSpeedGauge.la libCruiseManager.la libThrottle.la

libCruiseManager_la_SOURCES = ...

## Process this file with automake to produce Makefile.in

lib_LTLIBRARIES = libSpeedGauge.la
libSpeedGauge_la_SOURCES = SpeedGauge.c CruiseManager.c Throttle.c

bin_PROGRAMS = main
main_SOURCES = main.c
main_LDADD = libSpeedGauge.la

答案 1 :(得分:1)

lib_LTLIBRARIES是需要由Automake构建的库(与libtool一起使用)。您未能指定libSpeedGuage_la_SOURCES。有关如何操作的详细信息,请查看aaa的答案。

如果您只想引用已构建的库,请使用_LDADD(但省略lib_LTLIBRARIES指令)。