LNK2001 error when using namespace.... 
Author Message
 LNK2001 error when using namespace....

Hello,

Due to name collision I had to put some include files in a namespace.

#include "stdafx.h"
#include "..\Common2\string_helpers.h"
#include "BO_PSDInfoRetrieval.h"
#include "ahBO_PSDInfoRetrieval.h"
#include "ahPSDSink.h"
namespace PID
{
 #include "..\PSDMessages\PIDMessages.h"

Quote:
}

Doing so, I get the following link error:

Quote:
>>>>>>>>><

Compiling...
ahBO_PSDInfoRetrieval.cpp
Linking...
   Creating library Debug/BO_PSDInfoRetrieval.lib and object
Debug/BO_PSDInfoRetrieval.exp
ahBO_PSDInfoRetrieval.obj : error LNK2001: unresolved external symbol
"public: __thiscall PID::CPID_RSP_GetDeviceID::CPID_RSP_GetDeviceID(void)"

ahBO_PSDInfoRetrieval.obj : error LNK2001: unresolved external symbol
"public: __thiscall PID::CPID_CMD_GetDeviceID::CPID_CMD_GetDeviceID(unsigned

Removing file from namespace (and renaming classes/struct causing collision)
make the linker happy.
I have also checked that the #ifndef xyz are differant in both .h files.

Any ideas.... I'm getting nuts!

Jos



Sat, 21 Feb 2004 20:29:18 GMT  
 LNK2001 error when using namespace....
If you put a declaration of a class into a namespace, you should put an
implementation into this namespace, too. CPID_RSP_GetDeviceID and
PID::CPID_RSP_GetDeviceID are two different classes. That's what namespaces
are for, after all.
--
With best wishes,
    Igor Tandetnik


Quote:
> Hello,

> Due to name collision I had to put some include files in a namespace.

> #include "stdafx.h"
> #include "..\Common2\string_helpers.h"
> #include "BO_PSDInfoRetrieval.h"
> #include "ahBO_PSDInfoRetrieval.h"
> #include "ahPSDSink.h"
> namespace PID
> {
>  #include "..\PSDMessages\PIDMessages.h"
> }

> Doing so, I get the following link error:

> >>>>>>>>><
> Compiling...
> ahBO_PSDInfoRetrieval.cpp
> Linking...
>    Creating library Debug/BO_PSDInfoRetrieval.lib and object
> Debug/BO_PSDInfoRetrieval.exp
> ahBO_PSDInfoRetrieval.obj : error LNK2001: unresolved external symbol
> "public: __thiscall PID::CPID_RSP_GetDeviceID::CPID_RSP_GetDeviceID(void)"

> ahBO_PSDInfoRetrieval.obj : error LNK2001: unresolved external symbol
> "public: __thiscall

PID::CPID_CMD_GetDeviceID::CPID_CMD_GetDeviceID(unsigned

- Show quoted text -

Quote:

> Removing file from namespace (and renaming classes/struct causing
collision)
> make the linker happy.
> I have also checked that the #ifndef xyz are differant in both .h files.

> Any ideas.... I'm getting nuts!

> Jos



Sun, 22 Feb 2004 01:51:17 GMT  
 LNK2001 error when using namespace....
Thanks for the answer.
I'm not too sure I follow you when you say you have to put an implementation
into this namespace. The cpp file is used by other projects and I'm not
allowed to modified this cpp file.
Did I missed something?

Jose


Quote:
> If you put a declaration of a class into a namespace, you should put an
> implementation into this namespace, too. CPID_RSP_GetDeviceID and
> PID::CPID_RSP_GetDeviceID are two different classes. That's what
namespaces
> are for, after all.
> --
> With best wishes,
>     Igor Tandetnik



> > Hello,

> > Due to name collision I had to put some include files in a namespace.

> > #include "stdafx.h"
> > #include "..\Common2\string_helpers.h"
> > #include "BO_PSDInfoRetrieval.h"
> > #include "ahBO_PSDInfoRetrieval.h"
> > #include "ahPSDSink.h"
> > namespace PID
> > {
> >  #include "..\PSDMessages\PIDMessages.h"
> > }

> > Doing so, I get the following link error:

> > >>>>>>>>><
> > Compiling...
> > ahBO_PSDInfoRetrieval.cpp
> > Linking...
> >    Creating library Debug/BO_PSDInfoRetrieval.lib and object
> > Debug/BO_PSDInfoRetrieval.exp
> > ahBO_PSDInfoRetrieval.obj : error LNK2001: unresolved external symbol
> > "public: __thiscall

PID::CPID_RSP_GetDeviceID::CPID_RSP_GetDeviceID(void)"

- Show quoted text -

Quote:

> > ahBO_PSDInfoRetrieval.obj : error LNK2001: unresolved external symbol
> > "public: __thiscall
> PID::CPID_CMD_GetDeviceID::CPID_CMD_GetDeviceID(unsigned

> > Removing file from namespace (and renaming classes/struct causing
> collision)
> > make the linker happy.
> > I have also checked that the #ifndef xyz are differant in both .h files.

> > Any ideas.... I'm getting nuts!

> > Jos



Sun, 22 Feb 2004 02:43:28 GMT  
 LNK2001 error when using namespace....
When you wrap the header into a namespace, it now defines different classes
for which no implementation exists. Consider:

// A.h *******************************

class A
{
public:
    void f();

Quote:
};

// A.cpp ********************************

void A::f()
{

Quote:
}

// test1.cpp *****************************

#include "A.h"

void test1()
{
    // Compiles and links OK. Accesses ::A and ::A::f
    A a;
    a.f();

Quote:
}

// test2.cpp ********************************

namespace N
{
    #include "A.h"

Quote:
}

// This source file sees class N::A and method N::A::f.

void test2()
{
    // The linker complains. It knows about ::A and ::A::f,
    // but nothing about N::A and N::A::f
    N::A a;
    a.f();

Quote:
}

--
With best wishes,
    Igor Tandetnik


Quote:
> Thanks for the answer.
> I'm not too sure I follow you when you say you have to put an
implementation
> into this namespace. The cpp file is used by other projects and I'm not
> allowed to modified this cpp file.
> Did I missed something?

> Jose



> > If you put a declaration of a class into a namespace, you should put an
> > implementation into this namespace, too. CPID_RSP_GetDeviceID and
> > PID::CPID_RSP_GetDeviceID are two different classes. That's what
> namespaces
> > are for, after all.
> > --
> > With best wishes,
> >     Igor Tandetnik



> > > Hello,

> > > Due to name collision I had to put some include files in a namespace.

> > > #include "stdafx.h"
> > > #include "..\Common2\string_helpers.h"
> > > #include "BO_PSDInfoRetrieval.h"
> > > #include "ahBO_PSDInfoRetrieval.h"
> > > #include "ahPSDSink.h"
> > > namespace PID
> > > {
> > >  #include "..\PSDMessages\PIDMessages.h"
> > > }

> > > Doing so, I get the following link error:

> > > >>>>>>>>><
> > > Compiling...
> > > ahBO_PSDInfoRetrieval.cpp
> > > Linking...
> > >    Creating library Debug/BO_PSDInfoRetrieval.lib and object
> > > Debug/BO_PSDInfoRetrieval.exp
> > > ahBO_PSDInfoRetrieval.obj : error LNK2001: unresolved external symbol
> > > "public: __thiscall
> PID::CPID_RSP_GetDeviceID::CPID_RSP_GetDeviceID(void)"

> > > ahBO_PSDInfoRetrieval.obj : error LNK2001: unresolved external symbol
> > > "public: __thiscall
> > PID::CPID_CMD_GetDeviceID::CPID_CMD_GetDeviceID(unsigned

> > > Removing file from namespace (and renaming classes/struct causing
> > collision)
> > > make the linker happy.
> > > I have also checked that the #ifndef xyz are differant in both .h
files.

> > > Any ideas.... I'm getting nuts!

> > > Jos



Sun, 22 Feb 2004 03:47:21 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. LNK2001 error (class using template)???

2. Link error LNK2001 while using CView derivative in a DLL

3. error LNK2001: using CTime.Format

4. Link error using GetFileVersionInfoSize() (LNK2001)

5. HELP: LNK2001 error when using CList template

6. LNK2005 and LNK2001 errors using CString

7. Linking error LNK2001 when using template classes

8. using namespace std; ERROR

9. Errors-using namespace std;

10. using namespace std causes fatal error

11. using qualified namespaces causes Error 2352

12. Syntax error using namespace

 

 
Powered by phpBB® Forum Software