RE: Mixed managed C++ and native C++

T

Tian Min Huang

Hi Drew,

I suggest you to check whether you use the proper namespace in the .cpp
file.
Could you tell us the detailed error message? I believe it will be most
helpful if you can post some code snippet that can demonstrate the problem.

I look forward to hearing from you.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 
D

Drew

ClientEngine.h

namespace ClientEngine
{
public __gc class Engine
{
public:
Engine();
~Engine();

private:
CEngineMsgHandler* m_pClientMsgHandler;
CDEPrjMsgHandler* m_pServerMsgHandler;
};
}

ClientEngine.cpp (if this is in .h it works)

ClientEngine::Engine::Engine()
: m_pClientMsgHandler(new CEngineMsgHandler()),
m_pServerMsgHandler(new CDEPrjMsgHandler())
{
// deleted stuff
}

ClientEngine::Engine::~Engine()
{
// deleted stuff
}

MainWindow.cpp
Linking...
LINK : error LNK2020: unresolved token (06000006)
ClientEngine.Engine::.ctor
LINK : error LNK2020: unresolved token (06000007)
ClientEngine.Engine::Finalize
LINK : fatal error LNK1120: 2 unresolved externals
 
T

Tian Min Huang

Hello Drew,

The LNK2020 linker errors here indicate that the definitions for
Engine(.ctor) and ~Engine(Finalize) are missing. Based on my experience,
the problem may be caused by the following issues:

1. ClientEngine.cpp did not include ClientEngine.h. If so, please add the
following line to ClientEngine.cpp:

//ClientEngine.cpp file
#include "ClientEngine.h"

2. Either ClientEngine.h or ClientEngine.cpp is not added to the project,
so that they are not being linked. Please make sure these files are added.

I am standing by for your result.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 
Joined
Sep 2, 2005
Messages
1
Reaction score
0
Hello,

I have a similar problem. To minimice the source of problems, I made a prototype solution that generates the same error.

The prototype solution have two projects:
1) The first called "Libray", which I create using the Empty Project (.NET) wizard, and then changed the configuration type (in project properties) form "Application (.exe)" to "Static Library (.lib)".
2) And the second called "Console", which I create using the Console Application (.NET) wizard, and added the Library.lib created after making my "Library" project (in project properties/linker/input/additional dependencies).

Note that I require that the "Library" project has both, managed and unmanaged classes. So I created two classes in the "Library" project: "Managed" and "Standard". Below is the code:


"Console\Console.cpp":

#include "..\Library\Managed.h"
#include "..\Library\Standard.h"
using namespace System;
int main() {

Managed* managedPtr = new Managed();
Standard standard;
return 0;​
}


"Library\Managed.h":

#pragma once
#using <mscorlib.dll>
__gc class Managed {

public:
Managed(void);
~Managed(void);​
};


"Library\Managed.cpp":

#include ".\Managed.h"
Managed::Managed(void) {}
Managed::~Managed(void) {}


"Library\Standard.h":

#pragma once
class Standard {

public:
Standard(void);
~Standard(void);​
};


"Library\Standard.cpp":

#include ".\Standard.h"
Standard::Standard(void) {}
Standard::~Standard(void) {}


When I build the solution I get:
"Build output":
Linking...
LINK : error LNK2020: unresolved token (06000002) Managed::.ctor
LINK : error LNK2020: unresolved token (06000003) Managed::Finalize
LINK : fatal error LNK1120: 2 unresolved externals

What are I missing? Please help me.

Just in case, here are the compiler and linker options:

"Cosole" compiler command line:
/Od
/AI "C:\Solutions\SolveProblem\Debug"
/D "WIN32"
/D "_DEBUG"
/D "_MBCS"
/FD /EHsc /MTd /GS
/Fo"Debug/"
/Fd"Debug/vc70.pdb"
/W3 /nologo /c /Zi /clr /TP
/FU "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscor lib.dll"
/FU "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Syste m.dll"
/FU "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Syste m.Data.dll"

"Console" linker command line:
/OUT:"C:\Solutions\SolveProblem\Debug\Console.exe"
/INCREMENTAL /NOLOGO /DEBUG /ASSEMBLYDEBUG
/PDB:"C:\Solutions\SolveProblem\Debug/Console.pdb"
/FIXED:No
c:\projects\SolveProblem\Library\Debug\Library.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

"Library" compiler command line:
/Od /AI "c:\projects\SolveProblem\Library\Debug"
/D "WIN32"
/D "_DEBUG"
/FD /EHsc /MTd /GS
/Fo"Debug/"
/Fd"Debug/vc70.pdb"
/W3 /nologo /c /Zi /clr /TP

"Library" linker command line:
/OUT:"c:\projects\SolveProblem\Library\Debug/Library.lib"
/NOLOGO

Thancks
 
Last edited:

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

Top