0

I just added one function definition to a .h file and its implementation in its corresponding .cpp file. When I compiled it, I got this compiling error:

./query.so: undefined reference to `Recognizer::skip_one_char(std::string const&, std::string const&)'
collect2: error: ld returned 1 exit status

In Recognizer.h, I added this:

bool skip_one_char(const string &content, const string &tag);

And in Recognizer.cpp, I added this:

bool skip_one_char(const string &content, const string &tag){
     ...
     return false
 }

It seems everything is right, but why do I still this error:

undefined reference 

Also, before I added this additional function implementation to it, the package compiles and runs well.

1 Answer 1

4

In Recognizer.cpp you've declared a free-standing function named skip_one_char:

bool skip_one_char(const string &content, const string &tag){
   ...
   return false;
}

... I think what you intended to do was create a method in the Recognizer class with that name, i.e.:

bool Recognizer::skip_one_char(const string &content, const string &tag){
   ...
   return false;
}

... at least, that method is what the linker is looking for and can't find.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that might be the reason!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.