First, thank you for the GREAT software!
Second, i'm sorry about my poor English!
===================
--OS: WinXP SP3
--IDE: Code::Blocks svn 5911 + MinGW-3.4.5
CodeLite v2.0.3365 + MinGW-4.4.0
===================
My problem is that I copy a simple C project to C::B and it occurs some errors(see below), but the project works well under CodeLite v2.0 and it's compiled by gcc-3.4.x without any error under RedHat, please tell me what the reason is or where i did wrong!!Thanks!!The full build log is:
-------------- Build: Debug in binarytree ---------------
mingw32-gcc.exe -Wall -g -c "d:\我的文档\CodeBlocks Project\binarytree\main.c" -o obj\Debug\main.o
mingw32-g++.exe -o bin\Debug\binarytree.exe obj\Debug\main.o
obj\Debug\main.o: In function `main':
d:/我的文档/CodeBlocks Project/binarytree/main.c:13: undefined reference to `_init'
d:/我的文档/CodeBlocks Project/binarytree/main.c:14: undefined reference to `_pre_order'
d:/我的文档/CodeBlocks Project/binarytree/main.c:16: undefined reference to `_in_order'
d:/我的文档/CodeBlocks Project/binarytree/main.c:18: undefined reference to `_post_order'
d:/我的文档/CodeBlocks Project/binarytree/main.c:20: undefined reference to `_depth'
d:/我的文档/CodeBlocks Project/binarytree/main.c:20: undefined reference to `_count'
d:/我的文档/CodeBlocks Project/binarytree/main.c:21: undefined reference to `_destroy'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 2 seconds)
7 errors, 0 warnings
===================
And the project is:
binarytree.h:
#ifndef BINARYTREE_H
#define BINARYTREE_H
typedef struct node *link;
struct node {
unsigned char item;
link l, r;
};
link init(unsigned char VLR[], unsigned char LVR[], int n);
void pre_order(link t, void (*visit)(link));
void in_order(link t, void (*visit)(link));
void post_order(link t, void (*visit)(link));
int count(link t);
int depth(link t);
void destroy(link t);
#endif // BINARYTREE_H
binarytree.c:
#include <stdlib.h>
#include "binarytree.h"
static link make_node(unsigned char item)
{
link p = malloc(sizeof *p);
p->item = item;
p->l = p->r = NULL;
return p;
}
static void free_node(link p)
{
free(p);
}
link init(unsigned char VLR[], unsigned char LVR[], int n)
{
link t;
int k;
if (n <= 0)
return NULL;
for (k = 0; VLR[0] != LVR[k]; k++);
t = make_node(VLR[0]);
t->l = init(VLR+1, LVR, k);
t->r = init(VLR+1+k, LVR+1+k, n-k-1);
return t;
}
void pre_order(link t, void (*visit)(link))
{
if (!t)
return;
visit(t);
pre_order(t->l, visit);
pre_order(t->r, visit);
}
void in_order(link t, void (*visit)(link))
{
if (!t)
return;
in_order(t->l, visit);
visit(t);
in_order(t->r, visit);
}
void post_order(link t, void (*visit)(link))
{
if (!t)
return;
post_order(t->l, visit);
post_order(t->r, visit);
visit(t);
}
int count(link t)
{
if (!t)
return 0;
return 1 + count(t->l) + count(t->r);
}
int depth(link t)
{
int dl, dr;
if (!t)
return 0;
dl = depth(t->l);
dr = depth(t->r);
return 1 + (dl > dr ? dl : dr);
}
void destroy(link t)
{
post_order(t, free_node);
}
the main.c
#include <stdio.h>
#include "binarytree.h"
void print_item(link p)
{
printf("%d", p->item);
}
int main()
{
unsigned char pre_seq[] = { 4, 2, 1, 3, 6, 5, 7 };
unsigned char in_seq[] = { 1, 2, 3, 4, 5, 6, 7 };
link root = init(pre_seq, in_seq, 7);
pre_order(root, print_item);
putchar('\n');
in_order(root, print_item);
putchar('\n');
post_order(root, print_item);
putchar('\n');
printf("count=%d depth=%d\n", count(root), depth(root));
destroy(root);
return 0;
}
in additon:
My C::B can build and run others simple C projects success!!
And I change the C::B's toolchain into the CodeLite's MinGW-4.4.0, the project can NOT be compiled success!!