Need help debugging a project on C++

Code: https://github.com/Kaiser808/cpp

Assignment: https://filebin.net/d7wkeca4r1ydbsxx

I need help debugging these files. I got help from someone on Chegg on a assignment and they not responding anymore. The file doesn't run because it says on compiler that there are undefined symbols, but I included the required .h files in the module.cpp file (main program).
Maybe it would have been better to learn the material instead of cheating off Chegg.

Regardless, tell us the exact, full error messages you get, with file/line numbers, so we don't have to hunt them down ourselves.

Edit: I didn't see that you had an 'error.png' because you put in a link you called 'Assignment'.
Yes, as salem c mentioned, you are currently only attempting to compile module.cpp. There are other .cpp files you need to compile and then link.
Last edited on
> I got help from someone on Chegg
Did they give you build instructions?

Because from your picture, you're trying to build multiple files using the same idea that you would for a single file.

1. Build everything
 
$ g++ *.cpp


2. Build incrementally
1
2
$ for i in *.cpp ; do g++ -c $i ; done
$ g++ -o myprogram *.o

@Ganado

The assignment link contains a picture of the full error message
@salem c

I tried doing the g++ *.cpp method of compiling.
It doesn't show any error messages when I do that, but how do I run the program after performing that command on Terminal?
./myprogram
some say yes, some say no, but you can add the current folder to your profile so it will run without the silly ./ if you want to do that. It has a supposed security risk but like system() calls, the risk is low if this is just your home PC.
https://unix.stackexchange.com/questions/14812/how-to-change-profile-to-search-current-directory
> but how do I run the program after performing that command on Terminal?
Maybe start with 'ls' to see what new files showed up.

Typically, it's called 'a.out'

And you run it by doing
./a.out

How did you get so far without knowing how to run a program you just compiled?
@salem c
The issue is that when I try ./a.out or ./module, it says:
"error while opening file: No such file or directory" or "-bash: ./module: No such file or directory"
Last edited on
Does 'ls' show that one of those files exists?
@Ganado
After typing in ls in Terminal, it shows all of those files
Like this?

$ ls
and.h         greaterThan.h  module.cpp   or.h       subexpression.cpp  ternary.h
divide.h      lessThan.h     negation.h   parse.cpp  subexpression.h    times.h
equality.h    literal.h      operand.cpp  parse.h    symboltable.cpp    variable.cpp
expression.h  minus.h        operand.h    plus.h     symboltable.h      variable.h

# Compile all the files to produce a.out
$ g++ *.cpp
$ ls
and.h       expression.h   minus.h      operand.h  plus.h             symboltable.h  variable.h
a.out       greaterThan.h  module.cpp   or.h       subexpression.cpp  ternary.h
divide.h    lessThan.h     negation.h   parse.cpp  subexpression.h    times.h
equality.h  literal.h      operand.cpp  parse.h    symboltable.cpp    variable.cpp

# Compile each file separately to a .o file
$ for i in *.cpp ; do g++ -c $i ; done
$ ls
and.h         greaterThan.h  module.o     or.h       subexpression.cpp  symboltable.o  variable.o
a.out         lessThan.h     negation.h   parse.cpp  subexpression.h    ternary.h
divide.h      literal.h      operand.cpp  parse.h    subexpression.o    times.h
equality.h    minus.h        operand.h    parse.o    symboltable.cpp    variable.cpp
expression.h  module.cpp     operand.o    plus.h     symboltable.h      variable.h

# Then combine all .o files to make myprogram
$ g++ -o myprogram *.o
$ ls
and.h         greaterThan.h  module.o     operand.o  plus.h             symboltable.h  variable.h
a.out         lessThan.h     myprogram    or.h       subexpression.cpp  symboltable.o  variable.o
divide.h      literal.h      negation.h   parse.cpp  subexpression.h    ternary.h
equality.h    minus.h        operand.cpp  parse.h    subexpression.o    times.h
expression.h  module.cpp     operand.h    parse.o    symboltable.cpp    variable.cpp


> "error while opening file: No such file or directory"
That's because your program expects to find a file to open.
1
2
module.cpp:if (!fin.is_open())
module.cpp:perror("error while opening file");



$ ./a.out 
error while opening file: No such file or directory

$ touch input.txt
$ ./a.out 

Sure, it didn't do anything, because there's nothing in input.txt.
But it stopped carping about the missing file.

Now what goes in input.txt to make the program do something useful is anyone's guess.
Actually, it's your guess.

But since you didn't write the program, my guess is you're just as clueless about driving the program as you are about compiling and running.

Oh, and whoever "wrote" that code on cheggers couldn't be bothered to indent the code at all. It's a right dog's dinner.
Last edited on
It gets worse....

The muppet you got to help you on cleggers didn't know much more that you.

https://coderanch.com/t/737485/languages/undeclared-identifier-declared
Is a year old, and is the same code that you have, with indentation.

All your 'helper' did was act as a google copy/paste bot to feed you the result of a search.

> I got help from someone on Chegg on a assignment and they not responding anymore.
Because they don't know any more than how to google and fool you with a plausible answer.
Thanks a lot for the help @salem c
Topic archived. No new replies allowed.