Undefined symbols for architecture x86_64:

Pages: 12
Im trying to build a Library Management System and I am getting this error: Undefined symbols for architecture x86_64:.

Im not quite sure why I am getting this error. Can someone please help me fix this error.

The following link has a screenshot of the Xcode program showing the errors Im getting in more details. http://postimg.org/image/6ayuerz41/

The following is some of my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include<iomanip>
#include <string.h>
#include "Book.h"
//#include "DVD.h"
#include "Library.h"
//#include "Student.h"

using namespace std;

Library lib;
int main() {
//Student student;

	while(1)
	{
		char mainSelect;
		//char studentOption;
		char name[30];
		//char dvdOption;
		char bookOption;

		// Ask the user to select an option

		// Read user selection
		cin.getline( name, 80);
		mainSelect = name[0];

		// Switch statement to select between the options
		switch (mainSelect)
		{
		  case '1':
		    break;
		  case '2':
		    break;
		  case '3':
		    break;
		  case '4':
		    break;
		  case '5':
		    exit(0);
		    break;
		  case '6':
		    cout << "Invalid selection!" << endl;
		    break;
	    }

cin.getline(name, 80);
			bookOption = name[0];

			switch(bookOption)
			{
			  case '1':
			    //book.issueBook();
			    break;
			  case '2':
			    //book.returnBook();
			    break;
			  case '3':
			    lib.insertBook();
			    break;
			  case '4':
			    lib.updateBook();
			    break;
			  case '5':
			    lib.deleteBook();
			    break;
			  case '6':
			    char barcode[6];
			    cout<<"Enter The book barcode: " <<endl;
			    cin>>barcode;
			    lib.searchBook(barcode);
			    break;
			  case '7':
			    lib.showallBooks();
			    break;
			  case '8':
			    break;
			  case '9':
			    exit(0);
			    break;
			 }
		  }
return 0;
}
};


Main class Header:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 #ifndef Library_H_
#define Library_H_

class Library
{
public:
	void insertBook();
	void searchBook(char barcode[]);
	void updateBook();
	void deleteBook();
	void showallBooks();
};

#endif /* FINAL_H_ */ 


Book.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <stdlib.h>
#include <fstream>
#include <string.h>
#include <iostream>
#include<iomanip>
#include "Book.h"
//#include "Student.h"

using namespace std;
fstream lib, lib1, lib2;

//Student student;
Book book1;

void Book::insertBook()
{
	lib.open("book.dat",ios::out|ios::app);
	book1.newBook();
	lib.write((char*)&book1,sizeof(Book));
	lib.close();
}

void Book::searchBook(char barcode[6])
{
	int sys=0;
	lib.open("book.dat",ios::in);
	while(lib.read((char*)&book1,sizeof(Book)))
	{
		if(strcmp(book1.retBarcode(),barcode)==0)
		{
			book1.displayBook();
		 	sys=1;
		}
	}

	lib.close();
	if(sys==0)
		cout<<"Error: No such Book found in System." <<endl;

}

void Book::updateBook()
{
	int found=0;
	char barcode[6];
	cout<<"Enter barcode of the Book you want to update:" <<endl;
	cin>>barcode;
	lib.open("book.dat",ios::in|ios::out);
	while(lib.read((char*)&book1,sizeof(Book)) && found==0)
	{
		if(strcmp(book1.retBarcode(),barcode)==0)
		{
			book1.displayBook();
			cout<<"Enter New Book Details: "<<endl;
			book1.editBook();
			long pos=-1*sizeof(book1);
		    lib.seekp(pos,ios::cur);
		    lib.write((char*)&book1,sizeof(Book));
		    cout<<"Boobook1dated"<<endl;
		    found=1;
		}
	}

    	lib.close();
    	if(found==0)
    		cout<<"Error:Book Not Found. " <<endl;

}

void Book::deleteBook()
{
	char barcode[6];
	cout<<"Enter barcode of the Book you want to delete: " <<endl;
	cin>>barcode;
	lib.open("book.dat",ios::in|ios::out);
	lib2.open("Temp.dat",ios::out);
	lib.seekg(0,ios::beg);
	while(lib.read((char*)&book1,sizeof(Book)))
	{
		if(strcmp(book1.retBarcode(),barcode)!=0)
		{
			lib2.write((char*)&book1,sizeof(Book));
		}
	}

	lib2.close();
    	lib.close();
    	remove("book.dat");
    	rename("Temp.dat","book.dat");
    	cout<<"Book deleted." <<endl;

}

void Book::showallBooks()
{

	lib.open("book.dat",ios::in);
	if(!lib)
	{
		cout<<"Error: File could not be opened. " <<endl;

       		return;
     	}

	cout<<"Book Name"<<"Author"<<"Book Number"<<endl;

	while(lib.read((char*)&book1,sizeof(Book)))
	{
		book1.report();
	}
     	lib.close();

}


Book.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef BOOK_H_
#define BOOK_H_

#include <stdlib.h>
#include <iostream>
#include <fstream>
#include<iomanip>
#include "Media.h"

using namespace std;

class Book : public Media
{
	char author[20];

  public:
	void insertBook();
	void searchBook(char barcode[]);
	void updateBook();
	void deleteBook();
	void showallBooks();
	//void issueBook();
	//void returnBook();

	void newBook()
	{
		cout<<"Enter the Book Name: " <<endl;
		fgets(name, sizeof(name), stdin);
		cout<<"Enter the Name of Author: " <<endl;
		fgets(author, sizeof(author), stdin);
		cout<<"Enter the book barcode: " <<endl;
		cin>>barcode;
		cout<<"Book Added to the library" <<endl;
	}

	void displayBook()
	{
		cout<<"Enter the Book Name: " <<endl;
		puts(name);
		cout<<"Enter the Name of Author: ";
		puts(author);
		cout<<"Enter the Book barcode: " <<endl;
		cin>>barcode;
	}

	void editBook()
	{
		cout<<"Enter the Book Name you want to Update: " <<endl;
		cin>>barcode;
		cout<<"Enter New Book Name: " <<endl;
		fgets(name, sizeof(name), stdin);
		cout<<"Enter New Name of Author: " <<endl;
		fgets(author, sizeof(author), stdin);
	}

	void report(){
		cout<<"Name of Book: "<<name<<"Author of Book: "<<author<<"Barcode of Book: "<<barcode<<endl;
	}

};         //class ends here


#endif /* BOOK_H_ */ 
Last edited on
Could you please edit your post and use code tags? Code it unreadable - http://www.cplusplus.com/articles/jEywvCM9/
Last edited on
Any help?
Well looking at your errors, perhaps becuase you are using the main1 object to access functions for both DVD and Books? Are they both part of Main?

P.s. Dont call your stuff "main".
At the moment Im only using the Book function as I have commented out the DVD functions. Also I have renamed the Main.h to Library.h and also changed the class name to Library and created an object called lib but still I'm getting the same errors.
Could you updated your code with all the commented out stuff? Also, could you post the Main class header and cpp file?
I have updated my code and also added the other code files.
It looks like in the switch statement in main you're using the library class, yet you are showing all the code for the Book class and not the library class.
Sorry I don't quite understand what you are saying. Can you please elaborate.
Library lib;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
case '3':
			    lib.insertBook();
			    break;
			  case '4':
			    lib.updateBook();
			    break;
			  case '5':
			    lib.deleteBook();
			    break;
			  case '6':
			    char barcode[6];
			    cout<<"Enter The book barcode: " <<endl;
			    cin>>barcode;
			    lib.searchBook(barcode);
			    break;
			  case '7':
			    lib.showallBooks();
			    break;
			  case '8':


You are using the lib class as you can see.

But you have only posted the Book class. Not the Lib class. We still dont know what the Lib class looks like. If you're only using the lib class for now, then you dont need to show us the book class.

Oh sorry about that.

Library class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef Library_H_
#define Library_H_

class Library
{
public:
	void insertBook();
	void searchBook(char barcode[]);
	void updateBook();
	void deleteBook();
	void showallBooks();

};



#endif /* FINAL_H_ */ 
You have already showed that...

But you never show the cpp file for the Library class. Only the Book class, which you are not currently using so its pointless to show the book class at all.
There is no cpp file for Library class. I created a Library header file to define the functions used in the switch in the main file.
Thats why you are getting these errors... It makes no sense. You are calling the functions in the Library class, but they dont even exist.

lib.deleteBook();

When you do this. Here you're using a library object. When you use a library object, it means you're accessing functions from the library class. And they dont exist. So what are you expecting this to do?
Oh ok now I understand. But how can I use the functions from Book.cpp in the switch function in Main?
You would have to create a Book object.

Instead of Library lib;

create Book book;

And then use the book instead of library.

book.deleteBook();
Last edited on
But im already creating a book object in the Book cpp, so wouldnt it create any problems if I create another book object in the Main cpp?
No it wouldnt. A book object is just a book. You dont need to create a book object in book.cpp, it has no purpose.
I do need a book object in Book.cpp as I am using the object in several function in the Book.cpp.
You can just use the functions without an object since its in its own class...
Pages: 12