Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Export from DLL overloaded operator new

Posted on 2001-07-23
11
Medium Priority
?
1,066 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

876 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