News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Explicit library linking

Started by sheep, December 29, 2004, 12:38:25 AM

Previous topic - Next topic

sheep

Is there some linking option that won't automatically discard linked libraries that are not referenced at all in the main executable/library?

I am trying to create a component for the popular media player foobar2000 in assembly, the SDK says all components needed to be linked to utf8api.dll and libcurl.dl (whether or not they are utilized), and I have hit a snag that I think this might solve.

hutch--

sheep,

There is a trick to solve this problem. Write a procedure that is never called and put a sequence of calls to each procedure name.

call function1
call function2 etc ....

Absolutely don't run this procedure but by having the CALL code it should get everything from the library.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

sheep


rea

Can I question for what or from where come this? or fow what is in that way?, any toughts?

donkey

You can also just use LoadLibrary and don't call FreeLibrary until you exit your application.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

hutch--

rea,

Its a trick I learnt to defeat the linker characteristic of only including modules that are called in code. Its a good characteristic in most instances but not a lot of use when you want to use a library as a set of functions in a DLL.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

donkey

Hi Hutch,

Yeah, I use it to force-load the Rich Edit DLL in GoAsm by referencing the IID_ITextHost2 variable in RichEd20.DLL :

mov eax,[IID_ITextHost2]

GoLink will find the label in RichEd20 and load the DLL at startup. BTW RichEd20 is a good example of a DLL that must be loaded even though no functions are called.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

hutch--

We are actually talking about slightly different things here, what I have referred to is linking static library modules into an executable file when they are not directly called by code in the executable file. In a normal EXE file its good to remove such an addition which is what the linker will do but for example, I made a test piece with a DLL in MASM where I wanted the complete MASM32 library available as a set of functions in the DLL. Put all of the names in the EXPORT table but without any code that called them whatsoever.

The EXPORT table entries in the DEF file forced many to be included but not all so the next trick was to make a dead procedure that did a bare CALL to each name in the library which forced all of the library code to be included in the DLL and it tested up fine, everything worked and all of the right names were in the EXPORTS of the DLL.

With riched20.dll, ypou should be able to force its load with LoadLibrary() as per documentation. I wonder why you did it differently, is it to save on the LoadLibrary() call ?
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

donkey

No, not to save a LoadLibrary call but to stop my app from even starting if the DLL was not found and to display the standard Windows message telling the user that the DLL was not found. For myself it was a way of doing it without the LoadLibrary + Verify Return + Print Error Message hassle when Windows will do it for me and GoAsm/GoLink make it simple. I thought he was originally asking only about loading the DLL's even if they were not explicitly called, not statically linked libraries.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

rea

I will change a little my question :).

Im not able to understand this:
Quoteuse a library as a set of functions in a DLL

How or where when I do DLL I must warn that it should be included even if no direct calls are done????

Others questions: is not suficient to include one call for each DLL or is necesary to call each function in a DLL? Is there no a switch for the linker or some for control this behaviour and save a little space in the app;)?

donkey

You have only to call one function and the complete DLL will be loaded.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable