I have the following header file MappingSingleton.h:
#include <vector>
#include <string>
#include <fstream>
#include <iostream>
#include<iterator>
#include <sstream>
#include <thread>
#include <mutex>
#include "SOPExpr.h"
class MappingSingleton {
private:
    static MappingSingleton& mapping_singleton;
    MappingSingleton();
public:
    static unsigned int wireID;
    static bool is_init;
    std::vector<SOPExpr> m_hex_to_SOP_4;
    std::vector<int> m_hex_to_line_number_4;
    std::vector<SOPExpr> m_hex_to_SOP_3;
    std::vector<int> m_hex_to_line_number_3;
    std::vector<SOPExpr> m_hex_to_SOP_2;
    std::vector<int> m_hex_to_line_number_2;
    void loadLUTNHexToStringMapping(std::vector<SOPExpr>& m_hex_to_SOP, std::vector<int> &m_hex_to_line_number, short int LUT_size);
    std::string getQTPrims(std::string& LUT_init_string);
    static MappingSingleton getInstance();
private:
    static void initSingleton();
    static std::once_flag init_instance_flag;
    int getExprIndex(std::string &key, short lut_size);
    int wire_id;
};
And the following function in MappingSingleton.cpp:
MappingSingleton MappingSingleton::getInstance() {
    std::call_once(MappingSingleton::init_instance_flag,&MappingSingleton::initSingleton);
    return mapping_singleton;
}
The compiler gives the following error:
/grid/cva/p4_02/hisham/gcc/ua/Framework/Roman/src/MappingSingleton.cpp:37: undefined reference to `MappingSingleton::initSingleton()'
/grid/cva/p4_02/hisham/gcc/ua/Framework/Roman/src/MappingSingleton.cpp:37: undefined reference to `MappingSingleton::init_instance_flag'
/grid/cva/p4_02/hisham/gcc/ua/Framework/Roman/src/MappingSingleton.cpp:38: undefined reference to `MappingSingleton::mapping_singleton'
I don't understand why seeing as I have clearly defined those variables/functions in the header. I have tried reading many questions about this error, but none of the proposed solutions resolve the error. My main function just initializes Mapping Singleton.
MappingSingleton.cpp has the implementations:
#include "MappingSingleton.h"
#include "HelperFunction.h"
#include <regex>
#include <cmath>
#include "WireNameReplacement.h"
bool MappingSingleton::is_init=false; //this is static in the header file
std::once_flag init_instance_flag;
MappingSingleton::MappingSingleton() {
    wire_id=0; //used for avoiding duplicate wires.
    //Only one mapping generator at a time. Singleton design pattern.
        //Load mappings for the three LUTS
    loadLUTNHexToStringMapping(m_hex_to_SOP_4,m_hex_to_line_number_4,4);
    loadLUTNHexToStringMapping(m_hex_to_SOP_3,m_hex_to_line_number_3,3);
    loadLUTNHexToStringMapping(m_hex_to_SOP_2,m_hex_to_line_number_2,2);
}
 MappingSingleton MappingSingleton::getInstance() {
    std::call_once(MappingSingleton::init_instance_flag,&MappingSingleton::initSingleton);
    return mapping_singleton;
}
void MappingSingleton::loadLUTNHexToStringMapping(std::vector<SOPExpr>& m_hex_to_SOP, std::vector<int> &m_hex_to_line_number, short int LUT_size){
    //Read in Vivado Hex key of each SOP for LUT 4
    std::ifstream iFS("TextAndPythonFiles/LUT" +std::to_string(LUT_size)+"/lutListHex");
    std::string temp_str;
    m_hex_to_line_number.resize(pow(2,pow(2,LUT_size))); // 2^(2^4) for 4-LUT
    int tempInt=0;
    std::stringstream ss;
    while (std::getline(iFS, temp_str, '\n')) {
        m_hex_to_line_number[hexToInteger(temp_str)]=tempInt;
        ++tempInt;
    }
    //Read In the SOP Strings from a file. Reserve vector space first though to avoid reallocating vector. 
    //m_hex_to_SOP.resize(pow(2,pow(2,LUT_size)));
    std::ifstream iFS2("TextAndPythonFiles/LUT"+std::to_string(LUT_size)+"/combinedTrimmedFinal.vg");
    int tempInt2=0;
    std::string current_SOP;
    while (std::getline(iFS2, temp_str, '\n')) {
        if(temp_str.empty()) //Blank line implies new module
        {
            if(!current_SOP.empty()) current_SOP.pop_back(); //Erase last new line. Not necessary.
            SOPExpr expr(current_SOP);
            m_hex_to_SOP.push_back(expr);
            current_SOP.clear();
            continue;
        }
        current_SOP.append(temp_str);
        current_SOP.push_back('\n');
        tempInt2++;
    }
    //   createHexVec(line_num_to_SOP,m_hex_to_line_number); Reviewers please ignore
    std::string test="Q_OAI222 g514(.A0 (n_5), .A1 (n_0), .B0 (n_4), .B1 (n_1), .C0 (n_2), .C1 (n_3), .Z (n_6));\n Q_INV g517(.A (i0), .Z (n_5));Q_INV g518(.A (i2), .Z (n_4));";
    //std::cout<<findOutputWire(test);
}
std::string MappingSingleton::getQTPrims(std::string& vivado_LUT_string)
{
    //find LUT Size
    std::smatch match;
    std::regex re("LUT([0-9])");
    regex_search(vivado_LUT_string, match, re);
    int LUT_size=std::stoi(match.str(1));
    std::string key= extractHexKey(vivado_LUT_string);
    int expr_index;
    std::string qt_prims;
    std::deque<std::string> d;
    switch(LUT_size){
        case 2: expr_index= getExprIndex(key,2);
                qt_prims= m_hex_to_SOP_4[expr_index].getGateLevelNetList();
                d=findWireNames(vivado_LUT_string);
                qt_prims=replaceWireNames(d,vivado_LUT_string,qt_prims,2);
                replaceAllInternalWires(qt_prims,wire_id);
                return qt_prims;
        case 3: expr_index= getExprIndex(key,3);
                qt_prims= m_hex_to_SOP_4[expr_index].getGateLevelNetList();
                d=findWireNames(vivado_LUT_string);
                qt_prims= replaceWireNames(d,vivado_LUT_string,qt_prims,3);
                replaceAllInternalWires(qt_prims,wire_id);
                return qt_prims;
        case 4: expr_index= getExprIndex(key,4);
                qt_prims= m_hex_to_SOP_4[expr_index].getGateLevelNetList();
                d=findWireNames(vivado_LUT_string);
                qt_prims=replaceWireNames(d,vivado_LUT_string,qt_prims,4);
                replaceAllInternalWires(qt_prims,wire_id);
                return qt_prims;
        default:
            throw std::invalid_argument("Invalid LUT Init Val");
    }
    return "Invalid LUT Init Val";
}
int MappingSingleton::getExprIndex(std::string& key, short int LUT_size){
    switch(LUT_size){
        case 2: return m_hex_to_line_number_2[hexToInteger(key)];
        case 3: return m_hex_to_line_number_3[hexToInteger(key)];
        case 4: return m_hex_to_line_number_4[hexToInteger(key)];
        default:
            throw std::invalid_argument("Invalid LUT Init Val");
    }
}
 
    