为什么我的Xcode项目中出现链接器命令错误

时间:2018-09-20 06:02:37

标签: c++ xcode

我正在为学校做作业,但是遇到了Xcode的问题。我继续遇到的错误是

Undefined symbols for architecture x86_64:
  "JSONToken::print()", referenced from:
      JSONParser::parseJSONObject() in JSONParser.o
  "JSONToken::makeInt(int)", referenced from:
      JSONTokenizer::getToken() in JSONTokenizer.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这很令人困惑,因为我运行了代码并且运行得很好,但是我已经将文件输入到美化器中以确保其格式正确(因为我的老师对格式很挑剔),现在我遇到了这个错误。我什至回去取消了美化器所做的所有更改,甚至关闭并再次打开Xcode。我不知道为什么会发生这种情况,将不胜感激!

它抱怨的两个函数的代码在这里

EntityInstance JSONParser::parseJSONObject() {

    JSONToken token = tokenizer.getToken();

    if( ! token.isOpenBrace() ) {
        std::cout << "Error: JSONParser::parseJSONObject: Expected
    an open brace, but found" << std::endl;
        token.print();
        std::cout << "Terminating..." << std::endl;
        exit(1);
    }

    EntityInstance instance;

    do {
        Pair pair = parseAPair();
        instance.addAttribute(pair);
        token = tokenizer.getToken();
    } while( token.isComma() );

    if( ! token.isCloseBrace() ) {
        std::cout << "Error: JSONParser::parseJSONObject: Expected     
    an close brace, but found" << std::endl;
        token.print();
        std::cout << "Terminating..." << std::endl;
        exit(1);
    }

    return instance;
}

JSONToken JSONTokenizer::getToken(){

    char c;

    if( ! inputStream.is_open()) {
    std::cout << "Tokenizer::getToken() called with a 
    stream that is not open." << std::endl;
        std::cout << "Make sure that " << inputFileName << " exists 
    and is readable. Terminating.";
        exit(2);
    }

    while( inputStream.get(c)) {
        if(charOfInterest(c)) break;
    }

    JSONToken token;

    if( inputStream.eof() ) {
        token.endOfFile() = true;
        return token;
    }

    if(c == '['){
        token.isOpenBracket() = true;
        return token;
    } else if(c == ']') {
        token.isCloseBracket() = true;
        return token;
    } else if(c == '{'){
        token.isOpenBrace() = true;
        return token;
    } else if(c == '}') {
        token.isCloseBrace() = true;
        return token;
    } else if(c == ':') {
        token.isColon() = true;
        return token;
    } else if(c == ',') {
        token.isComma() = true;
        return token;
    } else if(c == '\"') {
        string attributeName = readAttributeName();
        token.makeAttributeName(attributeName);
        inputStream.get(c); 
        return token;
    } else if( c == 'n') {
        if(checkIfNull())
            token.isNull() = true;
        return token;
    } else if(isalnum(c)) {
        int newInt = readInt(c);
        token.makeInt(newInt);
        return token;
    }
    else {
        cout << "Not a valid Token" << endl;
    }
    return token;
}`

0 个答案:

没有答案