Solved

Export from DLL overloaded operator new

Posted on 2001-07-23
11
993 Views
Last Modified: 2008-02-20
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.
0
Comment
Question by:rssh
11 Comments
 

Expert Comment

by:rtenhove
ID: 6310460
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.
0
 

Author Comment

by:rssh
ID: 6310573
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
-----------------------------------------------
????????????????????????
0
 

Expert Comment

by:rtenhove
ID: 6311121
How are you setting EXPORTNEW_EXPORTS?

-Ron
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rssh
ID: 6311279
it's defined with the project...
in project setting, there is a preprocessor definitions
section where EXPORTNEW_EXPORTS is one of...
0
 

Expert Comment

by:rtenhove
ID: 6313351
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?
0
 

Author Comment

by:rssh
ID: 6313755
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
0
 

Expert Comment

by:rtenhove
ID: 6314128
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...

0
 

Expert Comment

by:rtenhove
ID: 6349857
have you figured out what the problem was yet?
0
 

Author Comment

by:rssh
ID: 6352013
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...
0
 
LVL 11

Expert Comment

by:griessh
ID: 6833133
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: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 6853135
Per recommendation points refunded and question closed.

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.net build a IF/Then Walkthrough Guide 1 278
C++ question 3 74
Gaming Software 1 28
learn programming 8 66
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question