【发布时间】:2020-04-29 22:19:31
【问题描述】:
我收到以下错误:
在 main 函数中: electionTestsExample.c:(.text+0xf7): 'main' 的多重定义 /tmp/cc5EeMIa.o:electionTestsExample.c:(.text+0xf7): 首先在这里定义
即使我只有一个主要功能 这是我的electionTestsExample.c:
#include <stdlib.h>
#include "elections.h"
#include "test_utilities.h"
/*The number of tests*/
#define NUMBER_TESTS 1
static bool deleteOnlyFirstArea (int area_id) {
return area_id == 1;
}
static bool testElectionRemoveAreas() {
Election election = electionCreate();
ASSERT_TEST(electionAddArea(election, 1, "first area") == ELECTION_SUCCESS);
ASSERT_TEST(electionAddArea(election, 2, "second area") == ELECTION_SUCCESS);
ASSERT_TEST(electionRemoveAreas(election, deleteOnlyFirstArea) == ELECTION_SUCCESS);
electionDestroy(election);
return true;
}
/*The functions for the tests should be added here*/
static bool (*tests[]) (void) = {
testElectionRemoveAreas
};
/*The names of the test functions should be added here*/
static const char* testNames[] = {
"testElectionRemoveAreas"
};
int main(int argc, char *argv[]) {
if (argc == 1) {
for (int test_idx = 0; test_idx < NUMBER_TESTS; test_idx++) {
RUN_TEST(tests[test_idx], testNames[test_idx]);
}
return 0;
}
if (argc != 2) {
fprintf(stdout, "Usage: election <test index>\n");
return 0;
}
int test_idx = strtol(argv[1], NULL, 10);
if (test_idx < 1 || test_idx > NUMBER_TESTS) {
fprintf(stderr, "Invalid test index %d\n", test_idx);
return 0;
}
RUN_TEST(tests[test_idx - 1], testNames[test_idx - 1]);
return 0;
}
这是我的生成文件:
CC=gcc
OBJS = electionTests.o election.o electionelem.o vote.o
EXEC = election
DEBUG_FLAG = -g
COMP_FLAG = -std=c99 -Wall -Werror
$(EXEC) : $(OBJS)
$(CC) $(DEBUG_FLAG) $(OBJS) -o $@
electionTests.o : electionTestsExample.c elections.h test_utilities.h
$(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
election.o : elections.c elections.h election_element.h votes.h map.h
$(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
electionelem.o : election_element.c election_element.h votes.h
$(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
vote.o : votes.c votes.h
【问题讨论】:
-
也许在其中一个包含中对
main()有另一种定义? -
没有一个没有主要功能
-
显示你的 Make-file 或编译指令。
-
我不是想举一个最小的例子
标签: c