1

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

2 回答 2

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
于 2011-02-14T22:34:42.477 回答
1

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

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

于 2011-02-14T22:44:38.500 回答