Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?未定义的符号 - 从头文件
显示功能,我知道这个问题得到回答所有的时间,但我一直没能找到我的具体实例的解决方案。这是完整的错误:
g++ main.cpp
Undefined symbols for architecture x86_64:
"Board::display()", referenced from:
_main in cc7hPZpy.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
我只是想从我的板类拉这个显示功能。这里的主:
#include "Board.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Some Asian Game" << endl;
Board base;
base.display();
//this is creating the error
//commenting it out compiles, but obviously does not do what i want.
return 0;
}
和Board.h:
#ifndef Board_H
#define Board_H
#include "Row.h"
#include <vector>
using namespace std;
class Board
{
public:
vector<Row> rows;
Board()
{
vector<Row> (15);
}
void play(int row, int col, char clr);
bool checkWin(int row, int col, char clr);
char getCellColor(int row, int col);
void display();
void empty();
};
#endif
和board.cpp
void Board::display()
{
for(int i=0;i<16;i++)
{
for(int i2=0;i2<16;i2++)
{
cout << rows[i].cells[i2].getState();
}
}
}
有关的特定功能我已经提到了这个网站经常寻找答案,但从未亲自使用过它,所以请耐心等待。我非常积极,这很简单,我只是忽略了。
哦,我用G ++在OSX –
是否http://stackoverflow.com/a/12574400/673730帮助吗?即你确定你正在编译'board.cpp'并链接到目标文件吗? (刚注意到你使用的命令行,不,你不是) –