NO

Author Topic: POLIB/POLINK BUG (workaround found)  (Read 6778 times)

runar

  • Guest
POLIB/POLINK BUG (workaround found)
« on: July 14, 2012, 09:35:03 AM »
Hello again;

    Last year tried to set up PellesC 6.50 as a SDL dev enviroment, and failed miserably  :-[. After doing all those tutorials say, i've been unable to compile any of the SDL sample programs, always with the 'error: unresolved external symbol' message.
    After running around like a chicken with his head cut-off for a while  :o, I deduced that it was the undescoring problem mentioned in http://forum.pellesc.de/index.php?topic=2809.msg11699#msg11699. Polib creates a NOT UNDERSCORED import library, and the compiler creates UNDERSCORED calls from the headers, thus, when it tries to link, the errors.

    Well, a year later, new SDL version, new PellesC version  :) and the same problem  :( :

    1-How can I force polib to underscore the functions? Don't see a flag to do so. If not posible, why not? And a more detailed answer that 'to better match Microsoft', because in VC (Microsoft Visual C) this seems to work with no trouble.  Not because I'm demanding, I'm just curious. ???

    2-How can I force the compiler to NOT underscore the calls? Is there a project option or a macro to be called on the headers to force this? Shouldn't it be?

    3-If none of those is possible, it is mentioned that if generating the import library from a DEF definition file of the dll, they are underscored correctly. How can I create the def file? (I mean aside to installed the MS Visual C++ compiler to be able to use the DLL Wizard mentioned there. I doubt my old Toshiba could handle it, even if it had the disk space for it).  Is there a small  tool for this?

    4-If there isn't, shouldn't that functionality be in polib too?  ::)

    And completely unrelated to the previos questions, I have a doubt  :P. When I use polib to /LIST the calls of a static library, all i get are a list of the obj files than make it (with the full path to those on the original machine). Shouldn't it list the functions inside those too?

    Please help everyone, sad panda is sad :'(

-- Edit --

    If you wanted me to guess, sorry for being a bit thick (it just took me a year and then some to figure out)  :'(.

I) Open a command line console: Start > Execute >
Code: [Select]
cmd.exe
II) Go to the directory where you have a copy of the DLL you want to make the import library.
In my case
Code: [Select]
cd "%UserProfile%\My documents\Pelles C Projects\SDLdemo.

III) Create a DEF file of the DLL. To do so, execute:
Code: [Select]
"%ProgramFiles%\PellesC\Bin\polib.exe" SDL.dll /MACHINE:X86 /OUT:SDL.lib
"%ProgramFiles%\PellesC\Bin\polib.exe" SDL.lib /MACHINE:x86 /MAKEDEF:SDL.def
"%ProgramFiles%\PellesC\Bin\polib.exe" SDL.lib /LIST
type SDL.def

IV) As you were shown by the two last commands, both the lib and the def file are NOT underscored. So that lib file won't link. Delete it.
Code: [Select]
delete SDL.lib

V) Recreate the lib file from the not-underscored def file like this:

Code: [Select]
"%ProgramFiles%\PellesC\Bin\polib.exe" SDL.lib /MACHINE:x86 /DEF:SDL.def
"%ProgramFiles%\PellesC\Bin\polib.exe" SDL.lib /LIST

As you have been shown, this lib file is automagically underscored.

To prove it, I've compiled several SDL examples that come with the code, and they have compiled and worked alright.

I hope they help someone, out there, in the depth of the internets.
« Last Edit: July 16, 2012, 03:11:49 AM by runar »

Offline Vortex

  • Member
  • *
  • Posts: 797
    • http://www.vortex.masmcode.com
Re: POLIB/POLINK trouble
« Reply #1 on: July 14, 2012, 11:37:15 AM »
Here is a quick test.

Create the module definition file :

Code: [Select]
LIBRARY test
EXPORTS

"funcA"
"_funcB"
"_func3@4"

Running polib.exe V7.00.0 :

Code: [Select]
polib /DEF:test.def /OUT:test.lib /MACHINE:x86
All the three functions will have a leading underscore.

Here is how they look inside the import library :

Code: [Select]
_func3@4
 __funcB
 _funcA
Code it... That's all...

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
May the source be with you

runar

  • Guest
Re: POLIB/POLINK trouble
« Reply #3 on: July 14, 2012, 05:44:39 PM »
Here is a quick test.

Create the module definition file :

Code: [Select]
LIBRARY test
EXPORTS

"funcA"
"_funcB"
"_func3@4"

Running polib.exe V7.00.0 :

Code: [Select]
polib /DEF:test.def /OUT:test.lib /MACHINE:x86
All the three functions will have a leading underscore.

Here is how they look inside the import library :

Code: [Select]
_func3@4
 __funcB
 _funcA

Sorry, but if you had read my question carefuly  you would have seen that I already knew that. From a DEF file it works as it should, it is when run from the DLL itself it is done incorrectly (or at least not in the way it espects to have feed it back later).

Thanks, though, because you inspired me for finding a workaround  ;) (pretty obvious anyway, but having it noted somewere, would have frustrated a lot less, both novices and users of other compiler families).

Read the first post again if you want to know.


Quote
How can I create the def file?
Look here:
http://forum.pellesc.de/index.php?topic=3700.msg13749#msg13749
http://forum.pellesc.de/index.php?topic=3272.msg12340#msg12340

Those helped a little, except that the obvious answer to your help would be to get the dlls with the functions to parse windows executables and make my own tool to do as I asked about. Good idea, except for the this: If I can't make correct import libraries, how would I use said DLLs in my tool? ::)

Thanks anyway.

runar

  • Guest
Re: POLIB/POLINK trouble (workaround found)
« Reply #4 on: July 14, 2012, 06:18:38 PM »
I'm sending working prebuilt lib files of the basic SDL libraries made by myself. :)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: POLIB/POLINK trouble (workaround found)
« Reply #5 on: July 15, 2012, 11:25:46 AM »
What workaround ?
Code: [Select]
polib.exe sdl.dll /OUT:sdl.lib /MACHINE:x86 makes that correct library ?
May the source be with you

Offline Vortex

  • Member
  • *
  • Posts: 797
    • http://www.vortex.masmcode.com
Re: POLIB/POLINK trouble (workaround found)
« Reply #6 on: July 15, 2012, 11:53:22 AM »
Hi runar,

It's very hot here and probably I missed the point. No any problem. timovjl's approach is correct. Polib creates correctly the import library. Open the .lib file with notepad and you will see all the leading underscores.
Code it... That's all...

runar

  • Guest
Re: POLIB/POLINK trouble (workaround found)
« Reply #7 on: July 16, 2012, 03:11:29 AM »
Hi runar,

It's very hot here and probably I missed the point. No any problem. timovjl's approach is correct. Polib creates correctly the import library.

Not always. I've had trouble creating the import lib from SDL.dll nearly without fail. Strangely, all the other SDL dlls (SDL_image, SDL_mixer, etc.) and others (unrar.dll, zlib1) have been done correctly.

Even better; if I try to generate the libs from a CMD script, they are underscored correctly.

Code: [Select]
for /r %%i in (.\dlls\SDL*.dll) do "%PellesC%\Bin\polib.exe" "%%i" /MACHINE:X86 /OUT:".\dlls\%%~ni.lib"
Right now, I'm generating them from the command line and it works. But this morning it didn't.

I'm using a Toshiba Satellite with Windows XP Home, OEM, fully updated. And I've rebooted several times since I uninstalled the old version (6.50 RC4) and installed the new one (7.00 final). Also have reinstalled once with a stock OEM disk (not a Toshiba one, so I could skip the bloatware) between 6.50 RC4 and now, so no corrupted installation to blame.

It is a completely random bug. Sometimes it pops up, sometimes doesn't. It is always with some specific dlls. The 2 previous versions (6.00, and 6.50) it happened the same with the same dlls, until one time they created it right and I stopped bitching complaining.

Last time (last year) it took me a week until it worked. That means that after I managed to create the lib file, I couldn't update the dlls to the latest versions, because the lib wouldn't match the dll. Well, technically I could due to SDL nature, whose interfaces doesn't change in the same version. The asociated dlls (sdl_mixer, sdl_net) can change arbitrary, though.

Still, I couldn't migrate to PellesC 7.00 RC3, RC4 or final because I was unable to recreate the import libraries. It has worked today, but the last 3 days it didn't. So, to me, that IS a bug. A damn hard one to reproduce, yes, undocumented, and until now, without a DOCUMENTED workaround to use in case it happened.

Open the .lib file with notepad and you will see all the leading underscores.

Yes, I know. Also you can see the underscores with
Code: [Select]
POLIB sdl.lib /LIST when polib doesn't act up and actually adds them.

Sorry if I seem to be ranting  ::) , but it seems a pretty pervasive bug, and I've not found other people with it (except maybe others that complained that they couldn't link with sdl.lib, but since they gave too litle detail it could have been because something else). And since it is so rare, and I can't find a reliable way to reproduce it, I can't report it. To compound the problem, english it is not my first language, so I can't make myself to be understood well enough. I don't know german or swedish either.  :-[

I don't know whether to laugh or cry. Do you hate me, Mr. Orinius? :'(

Anyway, I'm really thankful for your answers, Vortex and timovjl. I guess that I know who to bug for help in the forums. ;)

Have a good summer.
« Last Edit: July 16, 2012, 03:21:49 AM by runar »

czerny

  • Guest
Re: POLIB/POLINK BUG (workaround found)
« Reply #8 on: July 16, 2012, 06:43:42 PM »
What is the SDL version you have? 1.2.15?

runar

  • Guest
Re: POLIB/POLINK BUG (workaround found)
« Reply #9 on: July 16, 2012, 08:11:03 PM »
What is the SDL version you have? 1.2.15?

Yes. I've this bug happening to me with 1.2.12 too. Yet since it built last time (yesterday morning), it hasn't happened to me again, and I've ben making import libs for other dlls to test it. Having happened to me once, it would have called it a fluke, but twice... ???  Not so much . Yet I've not found any reason for it to happen.

And completely unrelated, what should I do to to get the direct x 9 libraries? I would like to try to compile SDL itself, and make static versions of the libraries (for single executable files).