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