Author Topic: DLL with alias function names  (Read 7694 times)

Offline michams

  • Single posting newcomer
  • *
  • Posts: 2
DLL with alias function names
« on: September 06, 2006, 04:48:57 pm »
Hi,

I'm building a simple dll and have a small Problem which is probably more a mingw than a CB problem. The DLL exports a function:

Code
bool DistributeValue(int *pValues)

which is exported automatically as

Code
_Z15DistributeValuePi

In VisualC++ its enough to place a def file with the alias in the source folder
Code
EXPORTS
   DistributeValue

With mingw/CB this is obviously not. What will I have to do to export the function with a name I want?

Env: WinXP, CB1.0 (31.08.06), mingw32 3.4.4

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: DLL with alias function names
« Reply #1 on: September 06, 2006, 05:35:28 pm »
Try adding -Wl,--add-stdcall-alias in the linker options for gcc to make it for you.
Alternatively, you can create a def file and add the linker option -Wl,--def [your_def] (IIRC).
Be patient!
This bug will be fixed soon...

Offline michams

  • Single posting newcomer
  • *
  • Posts: 2
Re: DLL with alias function names
« Reply #2 on: September 07, 2006, 08:17:27 am »
Hm, neither the first nor the second method has an effect to the exported symbols in my dll...  :?

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: DLL with alias function names
« Reply #3 on: September 07, 2006, 08:46:15 am »
if you want to build a dll with import names, that are consistent between different compilers, you need
to build it as C code, which then uses the C naming conventions.

use

Code
#ifdef __cplusplus
extern "C"
{
#endif
    .... // here are your exported function names
#ifdef __cplusplus
}
#endif


infos
http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html
« Last Edit: September 07, 2006, 08:48:33 am by tiwag »

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: DLL with alias function names
« Reply #4 on: September 07, 2006, 11:26:45 am »
her is a small project which demonstrates the differences

look at the generated .def files for name mangling info

HTH, tiwag

[attachment deleted by admin]

Offline severach

  • Multiple posting newcomer
  • *
  • Posts: 44
Re: DLL with alias function names
« Reply #5 on: September 11, 2006, 12:26:41 am »