importance of dllexport location in program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2008
Posts: 8
Reputation: gil_mo is an unknown quantity at this point 
Solved Threads: 0
gil_mo gil_mo is offline Offline
Newbie Poster

importance of dllexport location in program

 
0
  #1
May 9th, 2008
Hi,
(using MS VS2005) Recently I've found that in order for a function to be exported, dllexport *must* be placed in the same file of the function body. E.g. see the following case:

File a.cpp

  1. void dllexport a();
  2.  
  3. a();

File b.cpp

  1. void a()
  2. {
  3. // function body
  4. }

Now, a.cpp and b.cpp compile perfectly into a dll. However a() is not exported.
From what I understand from MSDN, dllexport is supposed to substitute the export section in the .DEF file - seems that it doesn't. Is this an MS bug?

Thanks,
Gil.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,340
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1455
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: importance of dllexport location in program

 
0
  #2
May 9th, 2008
Here is an explaination of how I use it. I always use it with __declspec and don't have a problem. It does not affect the .DEF file -- actually the DEF file is not even needed when dllexport is used.
Last edited by Ancient Dragon; May 9th, 2008 at 6:04 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 8
Reputation: gil_mo is an unknown quantity at this point 
Solved Threads: 0
gil_mo gil_mo is offline Offline
Newbie Poster

Re: importance of dllexport location in program

 
0
  #3
May 9th, 2008
Oh, of course, forgot to mention the __declspec. Well, it is there.
Try out the scenario I depicted and see that although no link problems, a() is not being exported.

Gil.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,340
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1455
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: importance of dllexport location in program

 
0
  #4
May 9th, 2008
Is b.cpp the application program that is calling the exported function in a.cpp, which is in a dll ?

In b.cpp you need to declare the function as _dllimport.
  1. // b.cpp is the application program
  2. //
  3. _delspec(_dllimport) void a();
  4.  
  5. void foo()
  6. {
  7. a();
  8. }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 8
Reputation: gil_mo is an unknown quantity at this point 
Solved Threads: 0
gil_mo gil_mo is offline Offline
Newbie Poster

Re: importance of dllexport location in program

 
0
  #5
May 10th, 2008
No, both a.cpp and b.cpp are files that compile into one dll. I did not specify the client to that dll.

Gil.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,340
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1455
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: importance of dllexport location in program

 
0
  #6
May 10th, 2008
>>From what I understand from MSDN, dllexport is supposed to substitute the export section in the .DEF file -

Your understanding is incorrect. What MSDN means is that you can export the function in one of two ways:
  • use the __dllspec( __dllexport ) tags
  • add an entry into the .DEF file

The compiler does not make any entries into the .DEF file for you -- you have to do that yourself if you want them there.

Prototyping the function as you did in a.cpp is not sufficient. You have to add dllexport in the function itself
  1. a.cpp
  2.  
  3. __dllspec( __dllexport ) void a()
  4. {
  5. // blabla
  6. }

You can also export an entire c++ class
  1. __dllspec( __dllexport) class MyClass
  2. {
  3. // blabla
  4. }
Last edited by Ancient Dragon; May 10th, 2008 at 10:15 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 8
Reputation: gil_mo is an unknown quantity at this point 
Solved Threads: 0
gil_mo gil_mo is offline Offline
Newbie Poster

Re: importance of dllexport location in program

 
0
  #7
May 10th, 2008
Well, it is also sufficient to place the function body in the same file as the *declaration*.
For example in my case, moving the function body from b.cpp to a.cpp without further changes would be enough to export the function.

I didn't see this behaviour specified in MSDN...

Thanks,
Gil.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC