Web lists-archives.com

Re: [Mingw-users] undefined reference to _imp__*




Hi Earnie,

I am new at MinGW and was not aware that DLLTOOL is no longer supported.

I had originally tried linking directly without the import library, but was getting "undefined reference" messages because the MinGW linker was expecting the prefix "_imp__" in front of all the imported symbol names, but the symbols in the DLL do not have this prefix.

The DLL exports its symbols using the STDCALL convention, so I assume I need to import them using STDCALL.  I wasn't seeing these linker errors when I tried to import using CDECL, but I was getting exceptions when I tried to run the code.  I don't believe it is valid to import symbols using CDECL if the DLL was exported with STDCALL, is it?

I do not have the luxury of rebuilding the DLL I am trying to import, so I am stuck with using STDCALL.  I believe life would be much easier if we were using CDECL, but that is not an option for me.




-----Original Message-----
From: Earnie [mailto:earnie@xxxxxxxxxxxxxxxxxxxxx] 
Sent: Wednesday, January 18, 2017 9:31 AM
To: mingw-users@xxxxxxxxxxxxxxxxxxxxx
Subject: Re: [Mingw-users] undefined reference to _imp__*

On 1/17/2017 5:25 PM, Cervinka, Mitch wrote:
> Okay.  Yes, I'm seeing the imp prefixes in the lib file.
> However, the underscores are wrong.
> 
> If I build the import library with DLLTOOL using the --no-leading-underscore option, and then use "nm -A" to examine the file, I see names like ...
> 
>           __imp_SYMBOL1            (i.e. 2 underscores before imp and 1 before the name)
> 
> If I build it without that option, the names look like this ...
> 
>           __imp__SYMBOL1            (i.e. 2 underscores before imp and 2 before the name)
> 
> However, the linker is looking for names like ...
> 
>           _imp__SYMBOL1            (i.e. 1 underscore before imp and two before the name)
> 
> 
> In other words, DLLTOOL seems to always prefix imp with two underscores, but the linker is looking for names where imp is prefixed by only a single underscore.
> 

Why are you using dlltool; it is no longer supported.

> I tried linking again, but am still seeing the "undefined reference" messages, due to the extra underscore.
> 
> Any insights on how to handle this?
> 

You don't need an import library.  You can link directly with the dll.

E. G.

If you have foo.dll in /PATH/TO/FOO then you can use

gcc -o foo.exe foo.o -L /PATH/TO/FOO -l foo

--
Earnie

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe