0

I get the "undefined reference to Mapmatcher::ransacMatches(cv::Mat, cv::Mat, Pose&)" linking error in my project. I tried to create an MWE as shown below and believe the error will be clear from that. My guess was that I needed to put Mapmatcher:: in front of the function, but as I declared it in class Mapmatcher{} it should not be necessary.

map_matcher_test_lib.h :

class Mapmatcher{
    public:
        Mapmatcher(void){};
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose);
};

map_matcher_test_lib.cpp :

#include "map_matcher_test/map_matcher_test_lib.h"
namespace map_matcher_test
{
//classes
    class Mapmatcher{
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose)
            {
                 // some code here...
            }
    };
}

map_matcher_test_node.cpp :

#include "map_matcher_test/map_matcher_test_lib.h"
Mapmatcher *mama = new Mapmatcher();
void mapMatcher()
{
    // matGlob, matLoc, result known here
    mama->ransacMatches(matGlob, matLoc, result);
}
int main (int argc, char** argv)
{
    // some stuff...
    mapMatcher();
}

Any help is appreciated.

EE-Student
  • 85
  • 1
  • 10

1 Answers1

2

You have class Mapmatcher once in your header file, and then another time in your source file, this is an error and violates the once definition rule. You should only have the class definition in your header file and implement the methods in the source file(s):

map_matcher_test_lib.h :

class Mapmatcher{
    public:
        Mapmatcher(void){};
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose);
};

map_matcher_test_lib.cpp :

#include "map_matcher_test/map_matcher_test_lib.h"
namespace map_matcher_test
{
    void Mapmatcher::ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose)
    {
        // some code here...
    }
}

Do make sure your class definition of Mapmatcher is inside the namespace in your header as well though.

Hatted Rooster
  • 35,759
  • 6
  • 62
  • 122