R
Rex_chaos
Hi all,
I am trying to compile a simple source to a library(.a). My code has
been seperated into two parts, header file and implementation.
// header file NSPWin.hpp
#ifndef __TESTLIB_H_
#define __TESTLIB_H_
#include <iostream>
#include <string>
namespace NSP
{
class NSPWin
{
private:
std::string name;
unsigned int lineNo;
public:
NSPWin(std::string sname, unsigned LN);
std::string getName(void);
friend std:stream& operator<<(std:stream &stream, NSPWin e);
}; // end class NSPWin
//Here is the implementation NSPWin.cpp
#include "NSPWin.hpp"
class NSPWin
{
private:
std::string name;
unsigned int lineNo;
public:
NSPWin(std::string sname, unsigned LN):name(sname), lineNo(LN)
{};
std::string getName(void)
{
return name;
}
friend std:stream& operator<<(std:stream &stream, NSPWin e)
{
stream << "The name is " << e.getName() << std::endl;
return stream;
}
}; // end class NSPWin
For testing, I have also written another code test.cpp
#include <iostream>
#include <stdlib.h>
#include "NSPWin.hpp"
int main(int argc, char *argv[])
{ NSP::NSPWin test("testing...", 23);
return 0;
}
I am using g++ under MsWindow and succeed in compiling the source code
to a library (NSPLib.a)
However, when I compile test.cpp and link the libary, it reports error
[Linker error] undefined reference to
`NSP::NSPWin::NSPWin(std::string, unsigned)'
Please help me!!!
I am trying to compile a simple source to a library(.a). My code has
been seperated into two parts, header file and implementation.
// header file NSPWin.hpp
#ifndef __TESTLIB_H_
#define __TESTLIB_H_
#include <iostream>
#include <string>
namespace NSP
{
class NSPWin
{
private:
std::string name;
unsigned int lineNo;
public:
NSPWin(std::string sname, unsigned LN);
std::string getName(void);
friend std:stream& operator<<(std:stream &stream, NSPWin e);
}; // end class NSPWin
//Here is the implementation NSPWin.cpp
#include "NSPWin.hpp"
class NSPWin
{
private:
std::string name;
unsigned int lineNo;
public:
NSPWin(std::string sname, unsigned LN):name(sname), lineNo(LN)
{};
std::string getName(void)
{
return name;
}
friend std:stream& operator<<(std:stream &stream, NSPWin e)
{
stream << "The name is " << e.getName() << std::endl;
return stream;
}
}; // end class NSPWin
For testing, I have also written another code test.cpp
#include <iostream>
#include <stdlib.h>
#include "NSPWin.hpp"
int main(int argc, char *argv[])
{ NSP::NSPWin test("testing...", 23);
return 0;
}
I am using g++ under MsWindow and succeed in compiling the source code
to a library (NSPLib.a)
However, when I compile test.cpp and link the libary, it reports error
[Linker error] undefined reference to
`NSP::NSPWin::NSPWin(std::string, unsigned)'
Please help me!!!