D
Daqian Yang
hello all
GCC gives me this error:
g++ -c -o x-main_a2.o x-main_a2.cpp
g++ -Wall -pedantic -c xfile_a2.cpp
g++ -Wall -pedantic x-main_a2.o xfile_a2.o -o x
Undefined first referenced
symbol in file
xf::Xfile::stats() x-main_a2.o
ld: fatal: Symbol referencing errors. No output written to x
collect2: ld returned 1 exit status
make: *** [x] Error 1
my programs contain 3 files. here are:
dragon:/home/cstudent/05/052203y/3773/a2> cat xfile_a2.cpp
#include "xfile_a2.h"
namespace xf{
Xfile::Xfile(string fname, int maxLineLength, int maxLines){
}
void compress() throw (runtime_error){
}
void stats() throw (runtime_error){
}
}
--
dragon:/home/cstudent/05/052203y/3773/a2> cat xfile_a2.h
#include <iostream>
#include <fstream>
#include <string>
#include <stdexcept>
using namespace std;
namespace xf{
class Xfile{
public:
Xfile(string = "mydata", int = 10, int = 10); //constructor
void compress() throw (runtime_error);
void stats() throw (runtime_error);
private:
typedef char* Xstr;
Xstr* storage_; //an array of array to store the data
int size_; //lines array contains
int length_; //length for each line
};
}
--
dragon:/home/cstudent/05/052203y/3773/a2> cat x-main_a2.cpp
#include <iostream>
using namespace std;
#include "xfile_a2.h"
int main(){
xf::Xfile x;
cout <<"before compressing"<<endl;
x.stats();
cout <<"after compressing"<<endl;
//x.compress();
//x.stats();
return 0;
}
---
GCC gives me this error:
g++ -c -o x-main_a2.o x-main_a2.cpp
g++ -Wall -pedantic -c xfile_a2.cpp
g++ -Wall -pedantic x-main_a2.o xfile_a2.o -o x
Undefined first referenced
symbol in file
xf::Xfile::stats() x-main_a2.o
ld: fatal: Symbol referencing errors. No output written to x
collect2: ld returned 1 exit status
make: *** [x] Error 1
my programs contain 3 files. here are:
dragon:/home/cstudent/05/052203y/3773/a2> cat xfile_a2.cpp
#include "xfile_a2.h"
namespace xf{
Xfile::Xfile(string fname, int maxLineLength, int maxLines){
}
void compress() throw (runtime_error){
}
void stats() throw (runtime_error){
}
}
--
dragon:/home/cstudent/05/052203y/3773/a2> cat xfile_a2.h
#include <iostream>
#include <fstream>
#include <string>
#include <stdexcept>
using namespace std;
namespace xf{
class Xfile{
public:
Xfile(string = "mydata", int = 10, int = 10); //constructor
void compress() throw (runtime_error);
void stats() throw (runtime_error);
private:
typedef char* Xstr;
Xstr* storage_; //an array of array to store the data
int size_; //lines array contains
int length_; //length for each line
};
}
--
dragon:/home/cstudent/05/052203y/3773/a2> cat x-main_a2.cpp
#include <iostream>
using namespace std;
#include "xfile_a2.h"
int main(){
xf::Xfile x;
cout <<"before compressing"<<endl;
x.stats();
cout <<"after compressing"<<endl;
//x.compress();
//x.stats();
return 0;
}
---