我已经开始编写一个非常简单的类,而且各种类的方法似乎给我带来了问题。我希望问题是我,解决方法很简单。C++编译问题; class methods
命令克++ -o主main.cpp中给出了如下因素输出:
/usr/bin/ld: Undefined symbols:
Lexer::ConsoleWriteTokens()
collect2: ld returned 1 exit status
main.cpp中:
#include<iostream>
#include"lexer.h"
int main(){
Lexer lexhnd = Lexer();
std::cout << "RAWR\n";
lexhnd.ConsoleWriteTokens();
std::cout << "\n\n";
return 0;
}
lexer.h:
#ifndef __SCRIPTLEXER
#define __SCRIPTLEXER
#include <iostream>
#include <string>
#include <vector>
#define DEF_TOKEN_KEYWORD 0
struct token{
int flag;
std::string data;
};
class Lexer
{
public:
// bool IsTrue();
// bool AddLine(char * line);
void ConsoleWriteTokens(void);
private:
std::vector<token> TOK_list;
};
#endif
lexer.cpp :
bool Lexer::IsTrue(){
return true;
};
bool Lexer::AddLine(char * line){
token cool;
cool.data = line;
TOK_list.push_back(cool);
string = line;
return true;
};
void Lexer::ConsoleWriteTokens(void){
for (int i = 0; i < TOK_list.size(); i++){
std::cout << "TOKEN! " << i;
}
return 0;
};
我在xcode btw中使用g ++。
Thankyou非常提前,我已经在这个问题上了几个小时。
编辑:
g++ -o main lexer.h main.cpp
or
g++ -o main lexer.cpp main.cpp
or
g++ -o main main.cpp lexer.cpp
就不能工作。 -Hyperzap
+1包含错误,您用于编译的命令和一个最小示例。一个非常好的问题。 – Tom 2011-05-06 13:35:33
我想你应该学会编写Makefiles或者使用automake/autoconf或者cmake或者qmake或者使用一个IDE来为你做任何事情。 – 2011-05-06 13:54:56