CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Threaded View

  1. #1
    Join Date
    Sep 2005
    Posts
    5

    Mixing managed and standard classes in a static library

    Hello,

    I need help to solve a link error. 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 by InMune; September 2nd, 2005 at 05:43 PM. Reason: make easyer to read

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured