Link to home
Start Free TrialLog in
Avatar of rssh
rssh

asked on

Export from DLL overloaded operator new

I overload "operator new" in a AdllA.dll
now I am trying to export it, so I can use
the "overloaded new" in BdllB.dll

I get this errors when I build AdllA.dll:
_________________________________________________________
Registry.cpp
udtmemalloc.h(19) : error C2375: 'new' : redefinition; different linkage
: see declaration of 'new'

udtmemalloc.h(21) : error C2375: 'delete' : redefinition; different linkage
: see declaration of 'delete'

Registry.cpp(38) : error C2264: 'new' : error in function definition or declaration; function not called

Registry.cpp(43) : error C2264: 'new' : error in function definition or declaration; function not called
----------------------------------------------------------

How do you export an overloaded new operator?

Thank you very much,

Rob H.
Avatar of rtenhove
rtenhove
Flag of United States of America image

You have to use import and export declarations.  This can done using the .DEF file, or in code:

You usually use a #define to keep things straight:

#define DLL_DECL __declspec( dllexport )
or
#define DLL_DECL __declspec( dllimport )

class DLL_DECL MyClass : public TObject { ...


You use the export form when building the DLL; you use the import form for modules that use (import) the DLL.
Avatar of rssh
rssh

ASKER

My question is regarding overloading global new
---------------------
so by doing this:
#ifdef EXPORTNEW_EXPORTS
#define EXPORTNEW_API __declspec(dllexport)
#else
#define EXPORTNEW_API __declspec(dllimport)
#endif

EXPORTNEW_API  void* operator new(unsigned int x);
-----------------------------------------------
I get this error:
exportnew.h(9) : error C2375: 'new' : redefinition; different linkage
-----------------------------------------------
????????????????????????
How are you setting EXPORTNEW_EXPORTS?

-Ron
Avatar of rssh

ASKER

it's defined with the project...
in project setting, there is a preprocessor definitions
section where EXPORTNEW_EXPORTS is one of...
You need to make sure that it is set differently when you are compiling the DLL, versus compiling the importer of the DLL.  You must tell the compiler you are exporting the class when you are compiling the DLL; likewise, you must tell the compiler you are importing the class when you are compiling "clients" that use the DLL.

Does this help?
Avatar of rssh

ASKER

Well, that's not the problem... all I am trying to do is export the new operator... and I keep getting the errors above... see new is already imported from some .lib file... the compiler comlains about some redefinition...
The problem you mentioned is already solved with the code above... thanx
Are you using the __declspec( dllexport ) on the new operator only?  

Perhaps you should post some snippet of your code, rather than just compiler error messages...

have you figured out what the problem was yet?
Avatar of rssh

ASKER

Acually I did ...
malloc and free can not go into a dll unless you take out the dependency on the lib file they're in... I think it's called msvctrd.lib or something similar...
You can make it work by adding them to a static linked library... but that gives 'different linkage' warings...
thanx anyway...
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and PAQ at zero points since you found your own answer.

The link to the Community Support area is: https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial