c - CUnit (undefined reference) -
c - CUnit (undefined reference) -
i need write programme using c , cunit test simple stack functions , using "makefile" when seek compile it, same errors. terminal on ubuntu show when write "make" command:
gcc -o pilhaa_teste.o pilhaa_teste.c -lcunit /tmp/cclqnqax.o: in function `main': pilhaa_teste.c:(.text+0x21): undefined reference `clean_suite1' pilhaa_teste.c:(.text+0x26): undefined reference `init_suite1' pilhaa_teste.c:(.text+0x50): undefined reference `testatop'
the .h wrote is:
typedef struct no { struct no *prox; int info; }no; typedef struct pilha { no *topo; }pilha; int init_suite1(void); int clean_suite1(void); void testatop(void); /*create empty stack*/ pilha *cria_pilha(void); /*add 1 element stack*/ void force (pilha *p, int valor); /*free first element of stack*/ void pop (pilha *p); /*print , find first element*/ int top (pilha *p); /*free stack*/ void libera(pilha *p); /*print stack*/ void imprime(pilha *p);
the .c main code:
#include <stdlib.h> #include <stdio.h> #include "pilha.h" #include "cunit/basic.h" int main(){ cu_psuite psuite = null; if (cue_success != cu_initialize_registry()) homecoming cu_get_error(); psuite = cu_add_suite("suite_1", init_suite1, clean_suite1); if(null == psuite){ cu_cleanup_registry(); homecoming cu_get_error(); } if(null == cu_add_test(psuite, "test of top()", testatop)){ cu_cleanup_registry(); homecoming cu_get_error(); } cu_basic_set_mode(cu_brm_verbose); cu_basic_run_tests(); cu_cleanup_registry(); homecoming cu_get_error(); }
and clean_suite1, init_suite1 , testatop functions:
static pilha *p = null; int init_suite1(void){ push(p, 6); if(p!=null) homecoming 0; else homecoming 1; } int clean_suite1(void){ pop(p); if (p == null) homecoming 0; else homecoming 1; } void testatop(void){ pilha *p = null; force (p, 6); if (p != null){ cu_assert(top(p) == 6); force (p, 7); if (p != null) cu_assert(top(p) ==7 ); } no *aux = p->topo->prox; free(p); free(aux); }
the basic functions, push, pop , others written there no problems them. used in programme of mine.
gcc -o
compiles , links sources, either add together .c functions implemented or compile separately gcc -c
, doesn't link source files.
c stack cunit
Comments
Post a Comment