体系结构x86_64的未定义符号:

Undefined symbols for architecture x86_64:

本文关键字:未定义 符号 x86 体系结构      更新时间:2023-10-16

接口:

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

实现:

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;
}

完整的错误消息是:

体系结构x86_64的未定义符号:"control::rmKeyControl::sm_function_list",引用自:control::rmKeyControl::addKeyAction(char,std::__1::function)在rm_KeyControl.o中ld:找不到体系结构x86_64的符号clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)

这似乎是Xcode 4的标准链接器错误,但它似乎是由于各种原因而发生的,而且从未详细说明。这个错误似乎表明存在在x86_64体系结构上不起作用的二进制指令,但在这种情况下没有意义。为什么我会出现此错误?

编辑:我忘了提到rmKeyControl在名称空间control中。我是实现中的using namespace control;,尽管您看不到它。

静态成员只是声明。在实现/源文件中定义它,如-

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