I have linking problems when building a managed c++ wrapper !!!!

G

Guest

Hi all,

I am very new to writing managed c++ wrapper for the existing unmanaged c++
class library.

I have a very simple existing unmanaged c++ class library with MFC CString
as a member variable. I try to write a managed c++ wrapper for the above
unmanaged c++ class library. But when I compile the managed c++ project, I
have all linking errors (Please see errors at the bottom). Below is my
simple unmanaged c++ class, managed c++ wrapper with their project
configurations. Is there anything wrong with my current project
configurations? What should I do to fix all linking errors? Please help…
Thanks so much.

Unmanaged c++ class: Un1.h (Here is my unmanaged c++ class. Built into
static library as UnManWin32.lib.

class CUn1
{
public:
CUn1(const CString& strName);
~CUn1();

void SetName(const CString& strName);
CString GetName();

private:
CString m_Name;
};

Configuration Type: Static Library (.lib)
Use of MFC: Use MFC in a Static Library
RunTime Library: Multi-threaded Debug (/MTd)

-------------------------------------------------------------------------------------
I found an article on the internet
(http://codeguru.com/cpp/cpp/cpp_managed/interop/print.php/c6867) that shows
to write a managed c++ wrapper.

I followed the steps to create a wrapper class as followed:
#pragma once

#include "Un1.h"
#include <atlstr.h>

#using <mscorlib.dll>
using namespace System::Runtime::InteropServices;
using namespace System;

namespace ManCL
{
public __gc class Class1
{
public:
Class1(String * strName);
void SetName(String * strName);
~Class1();
private:
CUn1 * m_pUn1;
};
}

Configuration Type: Dynamic Library (.dll)
Use of MFC: Use MFC in a Static Library
RunTime Library: Multi-threaded Debug (/MTd)
Additional Dependencies: msvcrtd.lib mscoree.lib UnManWin32.lib
Force Symbol references: __DllMainCRTStartup@12

When I compile the c++ managed wrapper project, I got below linking errors:
Linking...
LINK : warning LNK4098: defaultlib 'libcmtd.lib' conflicts with use of other
libs; use /NODEFAULTLIB:library
LINK : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO'
specification
uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator
new(unsigned int)" (??2@YAPAXI@Z) already defined in msvcrtd.lib(MSVCR71D.dll)
libcmtd.lib(dbgheap.obj) : error LNK2005: __malloc_dbg already defined in
msvcrtd.lib(MSVCR71D.dll)
libcmtd.lib(crt0.obj) : error LNK2005: __amsg_exit already defined in
msvcrtd.lib(MSVCR71D.dll)
LINK : warning LNK4199: /DELAYLOAD:OleAcc.dll ignored; no imports found from
OleAcc.dll
ManCL.obj : error LNK2001: unresolved external symbol "struct
ATL::IAtlStringMgr * __stdcall AfxGetStringManager(void)"
(?AfxGetStringManager@@$$FYGPAUIAtlStringMgr@ATL@@XZ)
libcmtd.lib(crt0.obj) : error LNK2019: unresolved external symbol _main
referenced in function _mainCRTStartup
C:\RTN\Codes\C++ Managed 3\ManCL\Debug\ManCL.dll : fatal error LNK1120: 2
unresolved externals
 

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