about creating a library

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::eek:stream& operator<<(std::eek: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::eek:stream& operator<<(std::eek: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!!!
 
J

Jack Klein

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_

Your program is ill-formed from the line above. Identifiers beginning
with an underscore and an uppercase letter, or containing two
consecutive underscores anywhere within them, are reserved for the
implementation in all contexts. Why do you think you need to begin
this macro name with two underscores?
#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::eek:stream& operator<<(std::eek: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::eek:stream& operator<<(std::eek: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!!!

You will need to ask this question in a gcc or Windows programming
group. Building and linking libraries are completely implementation
specific, and not defined by the language at all, so it is off-topic
here.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top