LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-17-2007, 04:12 AM   #1
strycnine
Member
 
Registered: Jul 2006
Location: Romania
Distribution: Fedora 12
Posts: 160

Rep: Reputation: 31
wierd_error


I have this program, made of 3 files:
lista.h:
Code:
#ifndef _LISTA_H_
#define _LISTA_H_


typedef char LOGIC;
#define ADEVARAT 1
#define FALS 0


struct lista {
				  int info;
				  struct lista *urm;
				  };
typedef struct lista Lista,*LISTA;


LISTA newl();

void destroyl(LISTA);

LISTA ins_la_inceput(LISTA,int);

LISTA sterge_primul(LISTA);

void afiseaza_lista(LISTA);

LOGIC este_vida(LISTA l);
#endif
functii.cpp
Code:
#include<stdlib.h>
#include<stdio.h>
#include<ctype.h>
#include "lista.h"


LISTA newl() {
	return NULL;
}



LISTA ins_la_inceput(LISTA l,int info) {
	LISTA p=(LISTA)malloc(sizeof(Lista));
	if(p!=NULL) {
		p->info=info; 
		p->urm=l;	  	
		return p;	  	
		}
	return l;	
}


LISTA sterge_primul(LISTA l) {
	// daca lista nu este vida
	if(l!=NULL) {
		LISTA p=l->urm;	
		free(l);		
		return p;	
	}
 
	return l;
}


void afiseaza_lista (LISTA l)	{

	if(l==NULL)
		printf("\n Lista este vida.");
	
	else {
		while(l!=NULL) {
			printf("%d ",l->info);
			l=l->urm;
		}
	}
}


LOGIC este_vida(LISTA l) {
	if(l==NULL)
		return ADEVARAT;
	else
		return FALS;
}

void destroyl(LISTA l) {
	if(l!=NULL) {
		// se parcurg toate elementele si se elibereaza spatiul ocupat de ele
		while(l!=NULL) {
			LISTA p=l;
			l=l->urm;
			free(p);
		}
	}
}
main.cpp:
Code:
#include<stdio.h>
#include<stdlib.h>
#include "functii.cpp"
#include "lista.h"
#include<ctype.h>



main()
{
	LISTA foaie;
	int nr;
	char j;
	puts("A.Insert at begining");
	puts("B.Del the first element");
	puts("C.List the list");
	puts("D.exit");
	scanf("%c", &j);
	switch(toupper(j))
	{
		case 'A':{
				printf("Insert number:");
	       			scanf("%d", &nr);
				foaie=ins_la_inceput(foaie, nr);
				break;
			 }
	 	case 'B':{
				sterge_primul(foaie);
			       	break;
			 }
		case 'C':{
		 		puts("Afisare lista");
	       			afiseaza_lista(foaie);
				break;
			 }
 		case 'D':{
				 exit(0);
			 }
	}
	return 0;
}
at compilation
$gcc -o prog main.cpp
$/tmp/ccxkDtqH.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
same with
$gcc -o prog main.cpp lista.h functii.cpp

thx
 
Old 05-17-2007, 04:32 AM   #2
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
Do you need to link in a libary file, this sort of problem is often caused by not calling a libary you need for one of the functions your using.
I'm a C programmer not really C++ but it also seems strange using #include "functii.cpp" if you need to use something from here I'd declare it as externs in in functii.h and call #include "functii.h"

Last edited by knobby67; 05-17-2007 at 04:35 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration