Search code examples
c++xcode4linker-errors

Undefined symbols for architecture x86_64:


interface:

class rmKeyControl {
    static map<char, function<char(char)>> sm_function_list;
public:
    static bool addKeyAction(char, function<char(char)>);
};

implementation:

bool rmKeyControl::addKeyAction(char key, function<char(char)> func) {
    if (!sm_function_list.count(key)) {
        sm_function_list.insert(pair<char, function<char(char)>>(key, func));
        return true;
    } return false;
}

The full error message is:

Undefined symbols for architecture x86_64: "control::rmKeyControl::sm_function_list", referenced from: control::rmKeyControl::addKeyAction(char, std::__1::function) in rm_KeyControl.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

This seems to be a standard linker error for Xcode 4, but it seems to occur for all sorts of reasons, and it never elaborates. This error seems to indicate the presence of binary instructions that don't work on the x86_64 architecture, but that doesn't make sense in this context. Why am I getting this error?

Edit: I forgot to mention that rmKeyControl is in namespace control. I am using namespace control; in the implementation, although you cannot see it.


Solution

  • Static member is just declaration. Define it in the implementation/source file like-

    // include interface header and then do -
    map<char, function<char(char)>> rmKeyControl::sm_function_list;