未定义的符号和未声明标识符的使用 我是一个新的C++程序员,我有一个C++文件,我想在MacBook Pro上安装MacOS Seela。当我第一次尝试使用以下工具编译它时: g++ -std=c++11 Main.cpp -o rpns

未定义的符号和未声明标识符的使用 我是一个新的C++程序员,我有一个C++文件,我想在MacBook Pro上安装MacOS Seela。当我第一次尝试使用以下工具编译它时: g++ -std=c++11 Main.cpp -o rpns,c++,c++11,g++,macos-sierra,clang++,C++,C++11,G++,Macos Sierra,Clang++,我得到了这个错误: Undefined symbols for architecture x86_64: "eval_expr(std::__1::stack<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::deque<std::__1::basic_string<char, std::__1::c

我得到了这个错误:

Undefined symbols for architecture x86_64:
"eval_expr(std::__1::stack<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::deque<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >&, std::__1::stack<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::deque<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >&, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, int> > >)", referenced from:
  _main in Main-2c97f0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Main.cpp:105:11: error: use of undeclared identifier 'stoi'
  ind = stoi(n, &sz);
      ^
Main.cpp:120:11: error: use of undeclared identifier 'stoi'
  ind = stoi(n, &sz);
      ^
Main.cpp:133:10: error: use of undeclared identifier 'to_string'
  return to_string(len);
     ^
Main.cpp:138:10: error: use of undeclared identifier 'to_string'
  return to_string(ind);
     ^
Main.cpp:146:9: error: use of undeclared identifier 'stoi'
  x = stoi(num1, &sz);
    ^
Main.cpp:147:9: error: use of undeclared identifier 'stoi'
  y = stoi(num2, &sz);
    ^
Main.cpp:155:11: error: use of undeclared identifier 'to_string'
  return to_string(x + y);
           ^
Main.cpp:163:9: error: use of undeclared identifier 'stoi'
  x = stoi(num1, &sz);
    ^
Main.cpp:164:9: error: use of undeclared identifier 'stoi'
  y = stoi(num2, &sz);
    ^
Main.cpp:172:11: error: use of undeclared identifier 'to_string'
  return to_string(x - y);
           ^
10 errors generated.
然后我得到了这个错误:

Undefined symbols for architecture x86_64:
"eval_expr(std::__1::stack<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::deque<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >&, std::__1::stack<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::deque<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >&, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, int> > >)", referenced from:
  _main in Main-2c97f0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Main.cpp:105:11: error: use of undeclared identifier 'stoi'
  ind = stoi(n, &sz);
      ^
Main.cpp:120:11: error: use of undeclared identifier 'stoi'
  ind = stoi(n, &sz);
      ^
Main.cpp:133:10: error: use of undeclared identifier 'to_string'
  return to_string(len);
     ^
Main.cpp:138:10: error: use of undeclared identifier 'to_string'
  return to_string(ind);
     ^
Main.cpp:146:9: error: use of undeclared identifier 'stoi'
  x = stoi(num1, &sz);
    ^
Main.cpp:147:9: error: use of undeclared identifier 'stoi'
  y = stoi(num2, &sz);
    ^
Main.cpp:155:11: error: use of undeclared identifier 'to_string'
  return to_string(x + y);
           ^
Main.cpp:163:9: error: use of undeclared identifier 'stoi'
  x = stoi(num1, &sz);
    ^
Main.cpp:164:9: error: use of undeclared identifier 'stoi'
  y = stoi(num2, &sz);
    ^
Main.cpp:172:11: error: use of undeclared identifier 'to_string'
  return to_string(x - y);
           ^
10 errors generated.
以下是我的Main.cpp代码:

#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <map>
#include <stdexcept>
using namespace std;

void init_map(map<string, int>& operatorToNumOperands);
string eval_expr(stack<string> &operands, stack<string> &operators, map<string, int> optor_to_num_opnd);
string operator_tilde(const string s1, const string s2);

string operator_right(const string s, const string n);

string operator_left(const string s, const string n);

string operator_len(const string& s);

string operator_find(const string& s, const string& f);

string operator_plus(const string num1, const string num2);

string operator_minus(const string num1, const string num2);

int main() {
   return 0;
}


void init_map(map<string, int>& operatorToNumOperands) {
}

string eval_expr(stack<string> &operands, stack<string> &operators, const map<string, int> &optor_to_num_opnd) {
  while(!operators.empty()) {
    int numOperands = optor_to_num_opnd.at(operators.top());
    vector<string> opands;
    while(numOperands > 0) {
      if(operands.empty())
        throw "not enough arguments given for: '" + operators.top() + "' operator";
      opands.push_back(string(operators.top()));
      numOperands--;
    }
    string expr_val = "";
    try {
        if(operators.top() == "~") {
          expr_val = operator_tilde(opands[1], opands[0]);
        } else if(operators.top() == "->") {
          expr_val = operator_right(opands[1], opands[0]);
        } else if(operators.top() == "<-") {
          expr_val = operator_left(opands[1], opands[0]);
        } else if(operators.top() == "#") {
          expr_val = operator_len(opands[0]);
        } else if(operators.top() == "?") {
          expr_val = operator_find(opands[1], opands[0]);
        } else if(operators.top() == "+") {
          expr_val = operator_plus(opands[1], opands[0]);
        } else  { 
          expr_val = operator_minus(opands[1], opands[0]);
        }
        operators.pop();
    } catch (const invalid_argument& ia) {
        throw invalid_argument("InvalidArgumentError: " + string(ia.what()) + "\n");
    } catch (const out_of_range& oor) {
        throw out_of_range("OutofRangeError" + string(oor.what()) + "\n");
    }
    operands.push(expr_val);
  }
  return string(operands.top());
}
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
void init_映射(映射和运算符对象映射);
字符串求值表达式(堆栈和操作数、堆栈和运算符、映射optor到num opnd);
字符串运算符_tilde(常量字符串s1、常量字符串s2);
字符串运算符_right(常量字符串s,常量字符串n);
字符串运算符_左(常量字符串s,常量字符串n);
字符串运算符_len(常量字符串&s);
字符串运算符_find(常量字符串&s、常量字符串&f);
字符串运算符(常量字符串num1,常量字符串num2);
字符串运算符_减号(常量字符串num1,常量字符串num2);
int main(){
返回0;
}
void init_映射(映射和运算符对象映射){
}
字符串求值表达式(堆栈和操作数、堆栈和运算符、常量映射和运算到数值){
而(!operators.empty()){
int numOperands=optor_to_num_opnd.at(operators.top());
矢量蛋白石;
while(numOperands>0){
if(操作数.empty())
抛出“没有为以下对象提供足够的参数:”+operators.top()+“'operator”;
opands.push_back(字符串(operators.top());
核虫--;
}
字符串expr_val=“”;
试一试{
if(operators.top()==“~”){
expr_val=运算符(opands[1],opands[0]);
}else if(operators.top()==“->”){
expr_val=运算符_right(opands[1],opands[0]);

}else if(operators.top()==”您将声明的
字符串求值表达式(堆栈和操作数,堆栈和运算符,映射optor\u到\u num\u opnd)
,但您实现了
字符串求值表达式(堆栈和操作数,堆栈和运算符,常量映射和optor\u到\u num\u opnd)
。请参阅函数定义的第三个参数中的额外
常量
?将其应用于转发声明,或删除转发声明,并在首次使用之前定义函数。nice catch@user4581301!我将其添加到转发声明中,但仍然会遇到op.Revert中列出的相同编译器错误到原始命令行。您可能仍然有链接错误,但原因不同。原始命令行仍然给出相同的链接错误。还缺少一个引用:`const map**&**optor\u to_num\u optnd`。省去了从实现中剪切并粘贴函数原型的麻烦,将其粘贴到当前forwar之上d声明。