Solved

Export from DLL overloaded operator new

Posted on 2001-07-23
11
986 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.

792 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