News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Decoration

Started by czerny, July 16, 2014, 11:10:40 AM

Previous topic - Next topic

czerny

I need some instructions concerning function decoration! I always have problems with that stuff.  :-[

I have some code which should link with the statistical software R 3.1.0

There exists a DLL an import library and the header files.

In the code I have used the function 'Rf_initEmbeddedR' with cdecl as project option.
Polink searches for '_Rf_initEmbeddedR' regardless of which switch is set -Gm or -Gn

I have tryed to explore the DLL and the LIB with podump /EXPORT

In the DLL: 23C   23B  6C70C0A0  Rf_initEmbeddedR
In the LIB: R.dll: _Rf_initEmbeddedR (__Rf_initEmbeddedR)

So there are the following questions:

How is it possible to avoid any decoration?
Neither the first entry nor the second (in braces) of the LIB is matching with the entry in the DLL. Why?
Which, the first or the second, should match? Or in other words: which is the exported name, which the name in the DLL?

EDIT: I suppose that the import library and DLL is produced by/for mingw. What are the differences?

frankie

If you have time read this.
Try to rebuild your import library using:
polib mylibrary.dll /OUT:mylibrary.lib
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

czerny

Quote from: frankie on July 16, 2014, 05:37:35 PM
polib mylibrary.dll /OUT:mylibrary.lib
Now it looks:

R.dll: Rf_initEmbeddedR (Rf_initEmbeddedR)

but the linker is always claiming for '_Rf_initEmbeddedR'

Vortex

You can try the NOUND option of Polib :

Quote/NOUND   Don't add underscore to import names
Code it... That's all...

czerny

#4
Quote from: Vortex on July 16, 2014, 07:40:07 PM
You can try the NOUND option of Polib :
Quote/NOUND   Don't add underscore to import names
This is by default! See (Yesterday at 05:48:29 PM).

Once more, I need to know what is what in the output of podump.

I propably need:
R.dll: Rf_initEmbeddedR (_Rf_initEmbeddedR)
or vice versa
R.dll: _Rf_initEmbeddedR (Rf_initEmbeddedR)

Dumpbin differentiates between 'function names' and 'symbol names'. Is it right, that Podump writes the second one in brackets?

How can I either prevent that the compiler uses underscrores in front of symbol names or produce an import library with underscores in symbol names.

Why is in the original import library the function name decorated by a single underscore, the symbol name decorated by two underscores, while the exported DLL name has no underscore at all in front of there names? Is this normal for mingw librarys?

frankie

In the header file specify that it is an imported function:
I.e. change from
int my func(int a);
to
__declspec(dllimport) int my func(int a);

If still you cannot link you have to define aliases in a def module:
As told in the previous post create your import library:
polib mydll.dll /OUT:MyDll.lib
Then get the definition file from library:
polib myDll.lib /MAKEDEF:MyDll.def
Edit the definition file adding your aliases:

LIBRARY "MyDll.dll"
EXPORTS
Rf_initEmbeddedR    ;Original export
_Rf_initEmbeddedR = Rf_initEmbeddedR    ; ALIAS. Now you will have two functions with different names
.......                                                             ;calling the same function
.......

Rebuild the import library with:
polib MyDll.lib /DEF:MyDll.def
Now you have a new import library with all required aliases.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

czerny

#6
I am very confused:
Quote from: frankie on July 17, 2014, 10:20:36 AM
polib mydll.dll /OUT:MyDll.lib
polib myDll.lib /MAKEDEF:MyDll.def
Edit the definition file adding your aliases:

LIBRARY "MyDll.dll"
EXPORTS
Rf_initEmbeddedR    ;Original export
_Rf_initEmbeddedR = Rf_initEmbeddedR    ; ALIAS. Now you will have two functions with different names
.......                                                             ;calling the same function
.......

Rebuild the import library with:
polib MyDll.lib /DEF:MyDll.def
After the first step:
polib mydll.dll /OUT:MyDll.lib
I have : R.dll: Rf_initEmbeddedR (Rf_initEmbeddedR)
After the other steps without editing anything I have: R.dll: Rf_initEmbeddedR (_Rf_initEmbeddedR)

Can someon explain?

frankie

Quote from: czerny on July 17, 2014, 11:05:22 AM
After the other steps without editing anything I have: R.dll: Rf_initEmbeddedR (_Rf_initEmbeddedR)

Can someon explain?
:(
It seems that, when using a def file, polib itself automatically generate correct decorated symbols...
But you haven't told us if you can link the DLL now!
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide