Payroll Program Debugging

Hi,

I'm working on a payroll program that uses OOP features. I'm aiming to read employee data from a text file and output net pay. I got an error message that I copied below and I need help interpreting it. I don't want a solution, I'm just looking for a hint on what top do next.

/*main.cpp*/

#include <iostream>
#include <fstream>
#include "employee.h"

using namespace std;

int main ()
{
ifstream myFile;
myFile.open("input.txt");
if (myFile.fail())
{
cout <<"File not found!"<< endl;
}
else
{
int count = 0;
Payroll p;

while (!myFile.eof()) {
string foo;
switch (count) {
case 0:
p.set_name(foo);
break;
case 1:
p.set_ID(stoi(foo));
break;
case 2:
p.set_hoursWorked(stod(foo));
break;
case 3:
p.set_wages(stod(foo));
break;

}
count++;

if (count % 4 == 0)
{
count = 0;
p.print_Payroll();
}
}
}
}


/*employee.cpp*/

#include <iostream>
#include "employee.h"

Payroll::Payroll(string n, int i, double hours, double wage)
{
name = n;
ID = i;
hoursWorked = hours;
wages = wage;

}

void Payroll::set_name(string n)
{
name = n;
}

string Payroll::get_name()
{
return name;
}
int Payroll::get_ID()
{
return ID;
}

void Payroll::set_ID(int i)
{
ID = i;
}

double Payroll::get_hoursWorked()
{
return hoursWorked;
}
void Payroll::set_hoursWorked(double hours)
{
hoursWorked = hours;
}

double Payroll::get_wages()
{
return wages;
}
void Payroll::set_wages(double wage)
{
wages = wage;
}

double Payroll::calculate_Salary()
{
double w = wages * hoursWorked;
}

void Payroll::print_Payroll()
{
cout << "Name "<< name << "ID "<< ID << "Salary "<< wages << endl;
}



/* employee.h*/

#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include <iostream>
using namespace std;


class Payroll
{
private:
string name;
int ID;
double hoursWorked;
double wages;

public:
Payroll();
Payroll(string n, int i, double hours, double wage);

double calculate_Salary (); //function call
void print_Payroll(); //function call

void set_name(string n);
string get_name();

int get_ID();
void set_ID(int i);

double get_hoursWorked();
void set_hoursWorked(double hours);

double get_wages();
void set_wages(double wage);
};



I got the following error message:

====================[ Build | PayrollProgram | Debug ]==========================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/username/CLionProjects/OOPC++Class/PayrollProgram/cmake-build-debug --target PayrollProgram -- -j 2
[ 50%] Linking CXX executable PayrollProgram
Undefined symbols for architecture x86_64:
"Payroll::print_Payroll()", referenced from:
_main in main.cpp.o
"Payroll::set_hoursWorked(double)", referenced from:
_main in main.cpp.o
"Payroll::set_ID(int)", referenced from:
_main in main.cpp.o
"Payroll::set_name(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
_main in main.cpp.o
"Payroll::set_wages(double)", referenced from:
_main in main.cpp.o
"Payroll::Payroll()", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [PayrollProgram] Error 1
make[2]: *** [CMakeFiles/PayrollProgram.dir/all] Error 2
make[1]: *** [CMakeFiles/PayrollProgram.dir/rule] Error 2
make: *** [PayrollProgram] Error 2
This looks like makefile/project settings problems, not code problems.
Maybe post your make-file, or double check it for issues, or try just a simple command line compile instead since it looks smallish?
It could be you targeted the wrong OS/CPU/Platform in there somewhere, but that could also just be triggered from a different issue.
Last edited on
Make file:

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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
[code][code][code]# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.13

# Default target executed when no arguments are given to make.
default_target: all

.PHONY : default_target

# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:


#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canonical targets will work.
.SUFFIXES:


# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =

.SUFFIXES: .hpux_make_needs_suffix_list


# Suppress display of executed commands.
$(VERBOSE).SILENT:


# A target that is always out of date.
cmake_force:

.PHONY : cmake_force

#=============================================================================
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake

# The command to remove a file.
RM = /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -E remove -f

# Escaping for special characters.
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /Users/username/CLionProjects/OOPC++Class/PayrollProgram

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /Users/username/CLionProjects/OOPC++Class/PayrollProgram/cmake-build-debug

#=============================================================================
# Targets provided globally by CMake.

# Special rule for the target rebuild_cache
rebuild_cache:
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
	/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache

# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache

.PHONY : rebuild_cache/fast

# Special rule for the target edit_cache
edit_cache:
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..."
	/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available.
.PHONY : edit_cache

# Special rule for the target edit_cache
edit_cache/fast: edit_cache

.PHONY : edit_cache/fast

# The main all target
all: cmake_check_build_system
	$(CMAKE_COMMAND) -E cmake_progress_start /Users/username/CLionProjects/OOPC++Class/PayrollProgram/cmake-build-debug/CMakeFiles /Users/usernamet/CLionProjects/OOPC++Class/PayrollProgram/cmake-build-debug/CMakeFiles/progress.marks
	$(MAKE) -f CMakeFiles/Makefile2 all
	$(CMAKE_COMMAND) -E cmake_progress_start /Users/username/CLionProjects/OOPC++Class/PayrollProgram/cmake-build-debug/CMakeFiles 0
.PHONY : all

# The main clean target
clean:
	$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean

# The main clean target
clean/fast: clean

.PHONY : clean/fast

# Prepare targets for installation.
preinstall: all
	$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall

# Prepare targets for installation.
preinstall/fast:
	$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast

# clear depends
depend:
	$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend

#=============================================================================
# Target rules for targets named PayrollProgram

# Build rule for target.
PayrollProgram: cmake_check_build_system
	$(MAKE) -f CMakeFiles/Makefile2 PayrollProgram
.PHONY : PayrollProgram

# fast build rule for target.
PayrollProgram/fast:
	$(MAKE) -f CMakeFiles/PayrollProgram.dir/build.make CMakeFiles/PayrollProgram.dir/build
.PHONY : PayrollProgram/fast

main.o: main.cpp.o

.PHONY : main.o

# target to build an object file
main.cpp.o:
	$(MAKE) -f CMakeFiles/PayrollProgram.dir/build.make CMakeFiles/PayrollProgram.dir/main.cpp.o
.PHONY : main.cpp.o

main.i: main.cpp.i

.PHONY : main.i

# target to preprocess a source file
main.cpp.i:
	$(MAKE) -f CMakeFiles/PayrollProgram.dir/build.make CMakeFiles/PayrollProgram.dir/main.cpp.i
.PHONY : main.cpp.i

main.s: main.cpp.s

.PHONY : main.s

# target to generate assembly for a file
main.cpp.s:
	$(MAKE) -f CMakeFiles/PayrollProgram.dir/build.make CMakeFiles/PayrollProgram.dir/main.cpp.s
.PHONY : main.cpp.s

# Help Target
help:
	@echo "The following are some of the valid targets for this Makefile:"
	@echo "... all (the default if no target is provided)"
	@echo "... clean"
	@echo "... depend"
	@echo "... rebuild_cache"
	@echo "... edit_cache"
	@echo "... PayrollProgram"
	@echo "... main.o"
	@echo "... main.i"
	@echo "... main.s"
.PHONY : help



#=============================================================================
# Special targets to cleanup operation of make.

# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
	$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_
check_[/code]build_[/code]system[/code]
Topic archived. No new replies allowed.