#undefined reference to

55 messages · Page 1 of 1 (latest)

stuck crater
#

Hello, can someone look at this main function and tell if there's really an "undefined reference" to basically any of these functions?
The photo is from my header file, and in the functions file i literally defined every each of them.
What's happening?

#include <cstring>
#include "functions.hpp"
#include <iostream>
#include <sstream>
#include <iomanip>
#include <random>

int main(int argc, char* argv[]) {
Node* root = nullptr;
int value;
srand((unsigned) time(NULL));
int i = rand();
char teststring[] = "add";
while (true){
if (argc > 1) {
if (std::strcmp(argv[i], "add" + value))
{
root = insert(root, value);
}
else if (std::strcmp(argv[i], "graph"))
{
printTree(root, 0);
}
else if (std::strcmp(argv[i], "remove" + value))
{
root = remove(root, value);
}
else if (std::strcmp(argv[i], "print"))
{
printAscending(root);
}
}
}
return 0;
}

snow roostBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

viscid bronze
#

What's the error message?

stuck crater
#

undefined reference to insert(Node*, int)' undefined reference to printTree(Node*, int)'
undefined reference to delete(Node*, int)' : undefined reference to printAscending(Node*)

everything in the file that i paste code here from

viscid bronze
#

(Wrap your message/code with ```code```)

stuck crater
#

#include <cstring>
#include "functions.hpp"
#include <iostream>
#include <sstream>
#include <iomanip>
#include <random>

int main(int argc, char* argv[]) {
Node* root = nullptr;
int value;
srand((unsigned) time(NULL));
int i = rand();
char teststring[] = "add";
while (true){
if (argc > 1) {
if (std::strcmp(argv[i], "add" + value))
{
root = insert(root, value);
}
else if (std::strcmp(argv[i], "graph"))
{
printTree(root, 0);
}
else if (std::strcmp(argv[i], "remove" + value))
{
root = remove(root, value);
}
else if (std::strcmp(argv[i], "print"))
{
printAscending(root);
}
}
}
return 0;
} ***

#

like this?

snow roostBOT
#
How to Format Code on Discord
Markup

```cpp
int main() {}
```

Result
int main() {}
noble ginkgo
#

try this

uneven nova
stuck crater
#

3 stars before and after in code you mean?

uneven nova
#

No

#

Backticks

#

` is not a star

stuck crater
#

o

#

h

#
#include <cstring>
#include "functions.hpp"
#include <iostream>
#include <sstream>
#include <iomanip>
#include <random>

int main(int argc, char* argv[]) {
    Node* root = nullptr;
    int value;
    srand((unsigned) time(NULL));
    int i = rand();
    char teststring[] = "add";
        while (true){
            if (argc > 1) {
                if (std::strcmp(argv[i], "add" + value))
                {
                    root = insert(root, value);
                }
                else if (std::strcmp(argv[i], "graph"))
                {
                    printTree(root, 0);
                }
                else if (std::strcmp(argv[i], "remove" + value))
                {
                    root = remove(root, value);
                }
                else if (std::strcmp(argv[i], "print"))
                {
                    printAscending(root);
                }
            }
        }
    return 0;
}```
noble ginkgo
#

and then, in front of first 3 backticks, write extension of language of your choice. in this case, cpp would be it

noble ginkgo
stuck crater
#

um

uneven nova
#

You can edit previous messages instead of posting a new one

uneven nova
noble ginkgo
#

there you go

stuck crater
#

;d

#

i didn't post here the file with these functions defined because i don't think it would make sense

uneven nova
#

remove pragma once

stuck crater
#

being honest it's the first time I'm using it

#

don't know much about it

uneven nova
#

#pragma once is non-standard

#

I tend to stay away from it

stuck crater
#

good to know

#

by the way, I'm also a fan of DB ;d

#

do you have an idea what I can chcange to don't have this error?

#

i meand undefined reference

faint lily
uneven nova
#

I just said my reason why

#

Didn’t say it was a terrible thing

#

I’m assuming you’ve defined those functions in functions.cpp

stuck crater
#

yep

#

exactly

uneven nova
#

how are you compiling

stuck crater
#

cmd

uneven nova
#

and what command(s) are you typing

stuck crater
#

g++ Source1.cpp

#

Source1 is the name of file with main

uneven nova
#

try g++ Source1.cpp functions.cpp

stuck crater
#

error: multiple definition of 'enum Color'

#

because it is in header file and in the functions file

#

i quess

uneven nova
#

What happens if you comment out the one in the functions.cpp file

stuck crater
#

wow

#

it has compiled

uneven nova
#

perfect timing, I have to go

stuck crater
#

thank you a lot