Odd error

My program was working fine last time I had worked on it. Though when I tried to run it, it failed to compile and gave an odd error message of 'relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Database::Database()'
Help?
This is what outputs when compiled:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cd 'C:\Users\Mouse\Documents\NetBeansProjects\Mpierce_CourseProject_080417'
C:\cygwin64\bin\make.exe -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/c/Users/Mouse/Documents/NetBeansProjects/Mpierce_CourseProject_080417'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/mpierce_courseproject_080417.exe
make[2]: Entering directory '/cygdrive/c/Users/Mouse/Documents/NetBeansProjects/Mpierce_CourseProject_080417'
mkdir -p dist/Debug/Cygwin-Windows
g++     -o dist/Debug/Cygwin-Windows/mpierce_courseproject_080417 build/Debug/Cygwin-Windows/Contact.o build/Debug/Cygwin-Windows/Database.o build/Debug/Cygwin-Windows/main.o 
build/Debug/Cygwin-Windows/main.o: In function `main':
/cygdrive/c/Users/Mouse/Documents/NetBeansProjects/Mpierce_CourseProject_080417/main.cpp:5: undefined reference to `Database::Database()'
/cygdrive/c/Users/Mouse/Documents/NetBeansProjects/Mpierce_CourseProject_080417/main.cpp:5:(.text+0x1e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Database::Database()'
collect2: error: ld returned 1 exit status
make[2]: *** [nbproject/Makefile-Debug.mk:65: dist/Debug/Cygwin-Windows/mpierce_courseproject_080417.exe] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/Mouse/Documents/NetBeansProjects/Mpierce_CourseProject_080417'
make[1]: *** [nbproject/Makefile-Debug.mk:61: .build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/Mouse/Documents/NetBeansProjects/Mpierce_CourseProject_080417'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2

BUILD FAILED (exit value 2, total time: 4s) 


Here's my program
Contact.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
#ifndef CONTACT_H
#define CONTACT_H
#include <cstdlib>
#include <vector>
#include <iostream>
#include <string>
using namespace std;

class Contact
{
private:
    string recNum;
    string firstName;
    string lastName;
    string address;
    string email;
    unsigned phoneNum;
    unsigned meeting;
    string notes;
public:
    Contact()
    {
    }
    
    Contact(string recIn , string fNameIn, string lNameIn, string addressIn, string emailIn, unsigned phoneNumIn, unsigned meetingIn, string notesIn)
            :recNum(recIn), firstName(fNameIn), lastName(lNameIn), address(addressIn), email(emailIn), phoneNum(phoneNumIn), meeting(meetingIn), notes(notesIn)
    {
    }
    
    void setRecNum(string recIn);
    void setFirstName(string fNameIn);
    void setLastName(string lNameIn);
    void setAddress(string addressIn);
    void setEmail(string emailIn);
    void setPhoneNum(unsigned phoneNumIn);
    void setMeeting(unsigned meetingIn);
    void setNotes(string notesIn);
    
    string getRecNum() const;
    string getFirstName() const;
    string getLastName() const;
    string getAddress() const;
    string getEmail() const;
    unsigned getPhoneNum() const;
    unsigned getMeeting() const;
    string getNotes() const;
};
ostream &operator<<(ostream &os, const Contact &contact);
#endif /* CONTACT_H */ 


Contact.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
#include "Contact.h"
#include <string>
using namespace std;

void Contact::setRecNum(string recIn)
{
    recNum = recIn;
}

void Contact::setFirstName(string fNameIn)
{
    firstName = fNameIn;
}

void Contact::setLastName(string lNameIn)
{
    lastName = lNameIn;
}

void Contact::setAddress(string addressIn)
{
    address = addressIn;
}

void Contact::setEmail(string emailIn)
{
    email = emailIn;
}

void Contact::setPhoneNum(unsigned phoneNumIn)
{
    phoneNum = phoneNumIn;
}

void Contact::setMeeting(unsigned meetingIn)
{
    meeting = meetingIn;
}

void Contact::setNotes(string notesIn) 
{
    notes = notesIn;
}

string Contact::getRecNum() const
{
return recNum;
}

string Contact::getFirstName() const
{
return firstName;
}

string Contact::getLastName() const
{
return lastName;
}

string Contact::getAddress() const
{
return address;
}

string Contact::getEmail() const
{
return email;
}

unsigned Contact::getPhoneNum() const
{
return phoneNum;
}

unsigned Contact::getMeeting() const
{
return meeting;
}

string Contact::getNotes() const
{
return notes;
}

ostream & operator<<(ostream & os, const Contact & contact)
{
    os  << "First Name    : " << contact.getFirstName() << endl
	<< "Last Name     : " << contact.getLastName() << endl
	<< "Address       : " << contact.getAddress() << endl
        << "Email         : " << contact.getEmail() << endl
	<< "Phone Number  : " << contact.getPhoneNum() << endl
        << "Meeting       : " << contact.getMeeting() << endl
        << "Notes         : " << contact.getNotes() << endl;

    os<< endl;
    return os;
}


Database.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
#ifndef DATABASE_H
#define DATABASE_H
#include "Contact.h"
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;

class Database
{
private:
    vector<Contact> contacts;
    int count;
    int entries;
    Contact contact;
public:
    Database();
    
    int getPeopleCount() const { return contacts.size(); }
    int getCount() const { count; }
    
    void addContact();
    void showContacts();
    void sortContacts();
    void searchContacts();
    void menu();
};


#endif /* DATABASE_H */ 


Database.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
#include "Database.h"
#include <stdexcept>
#include <algorithm>
#include <string>
using namespace std;

void Database::addContact()
{
    cout << "How many records do you want to input?: ";
    cin >> entries;
    
    cin.get();
    string temp;
    Contact tmpContact;
    for (int i = 0; i< entries; i++) 
    {
        cout << "What is the record number? ";
        getline(cin, temp);
        tmpContact.setRecNum(temp);
	cout << "What is the first name? ";
	getline(cin, temp);
	tmpContact.setFirstName(temp);
	cout << "What is the last name? ";
	getline(cin, temp);
	tmpContact.setLastName(temp);
        cout << "What is the address? ";
        getline(cin, temp);
        tmpContact.setAddress(temp);
        cout << "What is the email? ";
        getline(cin, temp);
        tmpContact.setEmail(temp);
        cout << "What is the phone number? ";
        getline(cin, temp);
        tmpContact.setPhoneNum(stoi(temp));
        cout << "When is the next meeting date? ";
        cout << "Please input in DD/MM/YYYY format";
        getline(cin, temp);
        tmpContact.setMeeting(stoi(temp));
        cout << "Please input any notes about this contact.";
        getline(cin, temp);
        tmpContact.setNotes(temp);
	contacts.push_back(tmpContact);
	++count; // increment count
	cout << endl;
    }
}

void Database::showContacts()
{
    if (count == 0) 
    {
	cout << "There are no entries yet!" << endl;
    }
    else 
    {
	cout << "Contact on record : " << count << endl;
	cout << "------------------------------------" << endl;
	for (auto &contact : contacts) 
        {
                cout << contact << endl;
	}
    }
    
}

void Database::menu()
{
    bool again = true;
    do 
    {
	int choice = 0;
	cout << "---Main Menu---\n";
	cout << "1. Input information\n";
	cout << "2. Display records\n";
	cout << "3. Exit\n";
	cout << "Your choice : ";
	try
        {
            cin >> choice;
            if(!(choice>=1 && choice<=3))
            {
                throw out_of_range("Your choice is out of range.");
            }
        }
        catch(out_of_range&)
        {
            cerr << "An error occurred. Please enter a valid menu number.\n";
            cin >> choice;
        }

	cin.get();
	switch (choice)
        {
	case 1:
            addContact();
            again = true;
            break;
	case 2:
            showContacts();
            again = true;
            break;
        case 3:
            cout << "Exiting program..." << endl;
            again = false;
            break;
        }
    } while(again);
}


main.cpp
1
2
3
4
5
6
7
#include "Database.h"
#include <cstdlib>
int main() 
{
    Database databases;
    databases.menu();
}
The constructor for Database is declared but not defined.
Database.h
line 17, constructor is declared.
 
    Database();



Database.cpp
Where is the constructor defined?
1
2
3
4
Database::Database()
{
    // whatever you like.
} 

It should be defined here somewhere.

@mbozzi
Sorry, I'm still trying to get used to programming in C++.
What do you mean not defined?

Edit, nevermind I found my error. Thank you! :)
Last edited on
Topic archived. No new replies allowed.