Link error new operator compiling a C++.NET dll

M

Michael Geyer

Hi there,

maybe this is a really stupid question...
One of the basic things in C++ is to allocate arrays like

char *bla = new char[19];

This compiles fine in a managed C++ class in a C++ application. But -
if I want to do the same thing in a managed Class in a DLL I get a
link error:

error LNK2001: unresolved external symbol "void * __cdecl operator
new(unsigned int)" (??2@$$FYAPAXI@Z)

(I only put the above line in the standard C++ .NET DLL project, that
appears if you choose "new project" in Visual Studio).
Using managed arrays works:

char ch __gc[] = new char __gc[19];

What am I doing wrong - is there a basic misunderstanding I have? Am I
not allowed to use good old unmanaged arrays in C++.NET ? Do I need
some libraries that are not linked to a DLL project by default?

Thanks in advance,

Michael
 
M

Michael Geyer

ok, I give the answer myself ;-)
Look for "Converting Managed Extensions for C++ Projects from Pure
Intermediate Language" in the Visual Studio C++.NET Documentation. Do
everything what it says to build a "DLL that contains consumers that
use managed code and DLL exports or managed entry points". If you want
to debug the project, fiddle around a bit with the debug properties of
the .NET DLL until all linker errors vanish.

Took me several days, but now it works!

A nice weekend to all,

Michael
 

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