Linker error

I have written a program that is separated as three different files. One file is the main, one with the class definition and one with all of the functions. The purpose is to separate a file of DVD's, but I am stuck. When I go to compile the function file, I get this error:

Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Help would be greatly appreciated.

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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include "DVD.hpp"

using namespace std;

DVD::DVD(){
    title = " ";
    year = 1800;
    actor = " ";
}
DVD::DVD(string new_title, int new_year, string new_actor){
    title = new_title;
    year = new_year;
    actor = new_actor;

}
DVD::DVD(string all_data){
    char a, b, c, d;
    //characters, one for each spot in the year;
    int p1, p2, p3;
    p1 = all_data.find("|");//finding where the | is;
    title = all_data.substr(0, p1); //finds title inside the string and sets it to title;
    all_data = all_data.substr(p1+1);
    
    p2 = all_data.find("|"); //finding where the second | is.
    p3 = all_data.length();
    actor = all_data.substr(p2+1, p3);//finds actor inside thr string and sets it to actor;
    all_data = all_data.substr(0, p2);
    
    a = all_data[0]- '0';
    b = all_data[1]- '0';
    c = all_data[2]- '0';
    d = all_data[3]- '0';
    //these four chars get assigned to the year. a becoming the first digit, b becoming the second, c becoming the third and d becoming the fourth;
    
    year = (a * 1000) + (b * 100) + (c * 10) + d;
    
    //since the chars are read in one at a time, we have to multiply them like so to recreate the year for our output.
    
}
void DVD::set_title(string new_title){
    title = new_title;
}

void DVD::set_year(int new_year){
    year = new_year;
}
void DVD::set_actor(string new_actor){
    actor = new_actor;
}

string DVD::get_title(){
    return title;
}
int DVD::get_year(){
    return year;
}
string DVD::get_actor(){
    return actor;
}
bool DVD::match_title(string target_title){
    
    string sub_title = title;
    string sub_target_title = target_title;
    char title_array[1000];
    
    for(unsigned int i = 0; i < sub_title.length(); i++){
        title_array[i] = sub_title[i];
    }
    for(unsigned int k = 0; k < sub_title.length(); k++){
        {
            
        }
        sub_title[k] = title[k];
    }
    
    char target_title_array[1000];
    
    for(unsigned int i = 0; i < sub_target_title.length(); i++){
        target_title_array[i] = sub_target_title[i];
    }
    for(unsigned int k = 0; k < sub_target_title.length(); k++){
        {
            
        }
        target_title[k] = sub_target_title[k];
    }
    if (sub_title.find(sub_target_title) != 999999)
        return true;
    else
        return false;
    
}
bool DVD::match_year(int the_year){
    ostringstream stream1;
    stream1 << year;
    string year = stream1.str();
    
    ostringstream stream2;
    stream2 << the_year;
    string target_year = stream2.str();
    
    if (year.find(target_year) != 999999)
        return true;
    else
        return false;
    
    
    
}
bool DVD::match_actor(string target_actor){
    string sub_actor = actor;
    string sub_target_actor = target_actor;
    char actor_array[1000];
    
    for(unsigned int i = 0; i < sub_actor.length(); i++){
        actor_array[i] = sub_actor[i];
    }
    for(unsigned int k = 0; k < sub_actor.length(); k++){
        {
            
        }
        sub_actor[k] = actor[k];
    }
    
    
char target_actor_array[1000];
    
    for(unsigned int i = 0; i < sub_target_actor.length(); i++){
        target_actor_array[i] = sub_target_actor[i];
    }
    for(unsigned int k = 0; k < sub_target_actor.length(); k++){
        {
            
        }
        target_actor[k] = sub_target_actor[k];
    }
    if (sub_actor.find(sub_target_actor) != 999999)
        return true;
        else
            return false;
        
}
bool DVD::match(string target){
    string year_string = to_string(year);
    if (match_title(target) == 1 || match_actor(target) == 1 || year_string.find(target) != 999999)
        return true;
    else
        return false;
    
}
void DVD::output(){
    cout << title << "|" << year << "|" << actor << endl;
}
Hi,

Can you please post:

* The compiler error verbatim, we want to see all the error, not part or your interpretation of it :+)
* The DVD.hpp file
* The main.cpp file

Some other things:

Consider using a member initialiser list in your constructors.

Why do you copy individual chars from a std::string to a char array?

Actually, I don't see the point of any of your match functions. It looks like a lot of unnecessary copying culminating in a find statement that is always false. What were you trying to do there?
http://www.cplusplus.com/forum/general/113904/

http://www.cplusplus.com/doc/tutorial/program_structure/
The function named main is a special function in all C++ programs; it is the function called when the program is run. The execution of all C++ programs begins with the main function, regardless of where the function is actually located within the code.
Topic archived. No new replies allowed.