B
bashill.zhu
Administrator@HILL /d/Users/Administrator/Desktop/tcplex/ch8/ex3_test
$ cat lexer.h
namespace Lexer
{
char get_char();
void foo();
}
$ cat lexer.cpp
#include "lexer.h"
#include <iostream>
namespace Lexer
{
extern std::istream* input;
int g_i;
}
char Lexer::get_char()
{
char ch;
g_i = 100;
input->get(ch);
return ch;
}
void Lexer::foo()
{
g_i = 200;
char c;
input->get(c);
return;
}
$ cat main.cpp
#include "lexer.h"
#include <iostream>
using namespace std;
istream* input;
int main()
{
input = &cin;
char ch = Lexer::get_char();
}
g++ -g -Wall -c lexer.cpp
g++ -g -Wall -c main.cpp
main.cpp: In function `int main()':
main.cpp:8: warning: unused variable 'ch'
g++ -o test.exe lexer.o main.o
lexer.o: In function `ZN5Lexer8get_charEv':
d:/Users/Administrator/Desktop/tcplex/ch8/ex3_test/lexer.cpp:12:
undefined reference to `Lexer::input'
lexer.o: In function `ZN5Lexer3fooEv':
d:/Users/Administrator/Desktop/tcplex/ch8/ex3_test/lexer.cpp:20:
undefined reference to `Lexer::input'
collect2: ld returned 1 exit status
make: *** [test.exe] Error 1
Could some one give me some help about this issue?
$ cat lexer.h
namespace Lexer
{
char get_char();
void foo();
}
$ cat lexer.cpp
#include "lexer.h"
#include <iostream>
namespace Lexer
{
extern std::istream* input;
int g_i;
}
char Lexer::get_char()
{
char ch;
g_i = 100;
input->get(ch);
return ch;
}
void Lexer::foo()
{
g_i = 200;
char c;
input->get(c);
return;
}
$ cat main.cpp
#include "lexer.h"
#include <iostream>
using namespace std;
istream* input;
int main()
{
input = &cin;
char ch = Lexer::get_char();
}
g++ -g -Wall -c lexer.cpp
g++ -g -Wall -c main.cpp
main.cpp: In function `int main()':
main.cpp:8: warning: unused variable 'ch'
g++ -o test.exe lexer.o main.o
lexer.o: In function `ZN5Lexer8get_charEv':
d:/Users/Administrator/Desktop/tcplex/ch8/ex3_test/lexer.cpp:12:
undefined reference to `Lexer::input'
lexer.o: In function `ZN5Lexer3fooEv':
d:/Users/Administrator/Desktop/tcplex/ch8/ex3_test/lexer.cpp:20:
undefined reference to `Lexer::input'
collect2: ld returned 1 exit status
make: *** [test.exe] Error 1
Could some one give me some help about this issue?