Xcode 7.3.1中的C++链接错误和未定义引用
C++ Linking Error and Undefined Reference in Xcode 7.3.1
所以我到处寻找这个问题的答案,但似乎找不到一个不是专门库的答案。我目前正在通过Stroustrup的原理和实践学习c++,虽然我通常在PC上使用visual studio,但我想在mac上用Xcode测试一下。出于某种原因,下面的代码出现了这篇文章底部复制的两个错误。
#include "libc++.h" // just a header file with the std library info copied from stroustrup's website
using namespace std;
string error(){
string s;
throw runtime_error(s);
}
class Token{
public:
char kind;
double value;
};
class Token_stream{
public:
Token_stream();
Token get();
void putback(Token t);
private:
bool full {false};
Token buffer;
};
void Token_stream::putback(Token t){
if(full) error("Full putback()");
buffer = t;
full = true;
}
Token Token_stream::get(){
if(full){
full = false;
return buffer;
}
char ch;
cin >> ch;
switch(ch){
case ';':
case 'q':
case '(': case ')': case '+': case '-': case '*': case '/':
return Token{ch};
case '.':
case '0': case '1': case '2': case '3': case '4':
case'5': case '6': case '7': case '8': case '9':
{ cin.putback(ch);
double val;
cin >> val;
return Token{'8', val};
}
default:
error("Bad Token");
}
return Token{0};
}
double expression();
Token_stream ts;
double primary(){
Token t = ts.get();
while(true){
switch (t.kind) {
case '(':{
double d = expression();
t = ts.get();
if(t.kind != ')') error("Expected ')'");
return d;
}
case 8:
return t.value;
default:
error("Primary value expected");
}
}
}
double term(){
double left = primary();
Token t = ts.get();
while(true){
switch (t.kind) {
case '*':
left *= primary();
t = ts.get();
break;
case '/':{
double d = primary();
if(d == 0) error("Bad input: Can not divide by zero.");
left /= primary();
t = ts.get();
}
default:
ts.putback(t);
return left;
}
}
}
double expression(){
double left = term();
Token t = ts.get();
while(true){
switch(t.kind){
case '+':
left += term();
t = ts.get();
break;
case '-':
left -= term();
t = ts.get();
break;
default:
ts.putback(t);
return left;
}
}
}
int main()
try {
while(cin)
cout << '=' << expression() << 'n';
}
catch(exception& e){
cerr << "error: " << e.what() << 'n';
}
我知道这并没有很好地记录下来,但这只是我在复习书中的练习。每当我尝试构建时,我都会出现这两个错误。
体系结构x86_64的未定义符号:"Token_stream::Token_sttream()",引用自:___cxx_global_var_init在main.o中ld:找不到体系结构x86_64的符号clang:错误:链接器命令失败,退出代码为1(使用-v查看>调用)
我想它希望我在构建阶段链接一些库,但我不知道我需要什么额外的库。此外,我的临时libc++只是因为我不知道如何在xcode中包含标准库,所以如果你觉得有额外的帮助,任何关于这方面的建议都会很好。非常感谢。
哇,我觉得自己像个白痴,因为我没有意识到这一点,但在发布后,我通读了代码,并在定义Token_stream类时意识到这是一个冗余。对于任何有同样问题的人来说,Stroustrup的例子在Token_stream{}中包含了Token_sttream(),这是错误的。
相关文章:
- 错误:未定义对cv::cudacodec::createVideoReader的引用
- Pybind11 错误未定义对"Py_GetVersion"的引用
- 纯虚拟类和错误未定义对 'vtable 的引用
- 为什么我会收到链接器错误:未定义对 ..?
- 链接错误:未定义对 stdscr 和 wgetch 的引用
- 尝试构建 xerces c++ 解析器。Netbeans 和命令行构建错误未定义对"xercesc_3_2..."的引用
- 错误:未定义的符号:gzclose opencv emscripten
- 我不断收到对项目"xxx"的错误未定义引用
- 我仍然收到此错误未定义的引用:boost::log::v2_mt_posix::trivial::logger::get
- 符号查找错误未定义的符号:curl_mime_init
- Omnet 和 Inet 链接错误:未定义对 typinfo 的引用
- 模拟 __name__ = __main__ 在 c++ 中会导致错误"未定义类似函数的宏"
- 链接器错误:未定义的引用C++
- OpenCv3.3安装错误-未定义对的引用
- CUDA 编译错误:未定义__hmul和__hneg
- C++错误:未定义对 (Winsock2.h) 的引用
- 错误:未定义对 .. 的引用.怎么了
- 无法生成项目,出现错误 - 未定义的体系结构符号 x86_64:"_JNI_CreateJavaVM"
- 编译错误:未定义的拱门
- C 编程原理和练习第7章练习4 symber_table :: get_value始终显示错误未定义