News:

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

Why using includelib?

Started by Sergiu FUNIERU, February 23, 2010, 06:31:52 PM

Previous topic - Next topic

Sergiu FUNIERU

When I compile the following code with JWasm, I get the same result, no matter if I use includelib or not. If that's the case, what's the advantages of using includelib?



...
include c:\masm32\include\windows.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\kernel32.inc

; includelib c:\masm32\lib\user32.lib
; includelib c:\masm32\lib\kernel32.lib
...



qWord

includelib informs the linker in which library's to search for unresolved symbols/functions - in case of user/kernel32.lib this are dynamic linked functions. As long as you don't use any function from the corresponding DLL, it doesn't mater if you specify it or not.
FPU in a trice: SmplMath
It's that simple!

Sergiu FUNIERU

Here's the complete code (it's from the example folder)
.586
.model flat, stdcall
option casemap :none   ; case sensitive

include c:\masm32\include\windows.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\kernel32.inc

; includelib c:\masm32\lib\user32.lib
; includelib c:\masm32\lib\kernel32.lib

.code
start:

    jmp @F
szDlgTitle db "Test Window", 0
szMsg db "It Works! ", 0
    @@:

     invoke MessageBox, 
      0,                
      ADDR szMsg, 
      ADDR szDlgTitle,
      MB_OK

     invoke ExitProcess,
      0

end start


Looking with a disassembler, I see this:
+++++++++++++++++++ IMPORT MODULE DETAILS +++++++++++++++++

   Import Module 001: KERNEL32.DLL

Addr:00002074 hint(0001) Name: ExitProcess

   Import Module 002: USER32.DLL

Addr:00002082 hint(0001) Name: MessageBoxA

This doesn't mean that I'm using function from the dlls I'm not linking to? I assumed that JWasm included automatically the necessary references, but, in this case, why should I manually use includelib?

qWord

how do you call the linker? I've not heard about such an feature of jwasm.
FPU in a trice: SmplMath
It's that simple!

Sergiu FUNIERU

Quote from: qWord on February 23, 2010, 07:22:23 PMhow do you call the linker? I've not heard about such an feature of jwasm.
jwasm index.asm
wlink system nt file index.obj

jj2007

Quote from: Sergiu FUNIERU on February 23, 2010, 06:31:52 PM
When I compile the following code with JWasm, I get the same result, no matter if I use includelib or not. If that's the case, what's the advantages of using includelib?

Sergiu,
includelib user32.lib (for example) means "give assembler & linker a chance to use the functions of user32.dll". Whether they actually need it is of minor importance. Many here in the forum use this:

include \masm32\include\masm32rt.inc

.code
start: MsgBox 0, "Hello World", "Masm is easy:", MB_OK
invoke ExitProcess, 0

end start


masm32rt.inc includes a bunch of typically used libraries, plus the macros like print, MsgBox etc., and certain standard settings. Just open the file in an editor to see what it does.

Purists prefer a long list of tailored include/includelib statements, sometimes with the argument that ml.exe has to work unnecessarily hard if it loads so many unused libraries. Timings show, though, that it slows assembly down by only a handful of milliseconds.

Vortex

Hi Sergiu,

Jeremy Gordon's linker Golink does not require the usage of import libraries. It's enough to specify the DLLs :

\Jwasm\Jwasm -c -coff Dlgbox.asm
\Goasm\Gorc /r Rsrc.rc
\Goasm\Golink /entry _start Dlgbox.obj Rsrc.res kernel32.dll user32.dll

Sergiu FUNIERU

I understand why some people will use one big include file, while other will list individually what to link to. But I didn't use ANY includelib in my asm file, yet it created a valid exe.
I suppose this happened due to the way that the obj file was linked, but, in this case, why using includelib at all when the linker is smart enough to figure out what to link?
Or only wlink is smart enough to do that and other linkers need to be told explicitly?

Off topic:
Please don't consider me rude, but either you use my correct first name (Sergiu) or not call me by name at all. If you call me Sergui or Sergio instead of Sergiu, someone who will read your post will propagate the wrong version. This went that far that when I asked for a credit card, I said "It's Sergio, but the last letter is "U"". Guess what? I received my credit card with my name written as Sergiou. It was my mistake, but I didn't think of that combination.  :bg

dedndave

you've had a troubled life, Sergiu   :P
that's odd, because you don't look like a criminal or anything
maybe you walk like a criminal - lol

i once bought a pick-up truck and the DMV put a "5" in the VIN instead of an "S"
my title did not match my truck
boy - that was hard to get fixed

Sergiu FUNIERU

Quote from: dedndave on February 23, 2010, 08:26:08 PMyou've had a troubled life, Sergiu   :P
Tell me about it!



Quote from: dedndave on February 23, 2010, 08:26:08 PMthat's odd, because you don't look like a criminal or anything
Except for being skinhead. I cut my hair to avoid pulling it while learning asm.



Quote from: dedndave on February 23, 2010, 08:26:08 PMmaybe you walk like a criminal - lol
No, I sit on the chair all day, trying to do killer programs.



Quote from: dedndave on February 23, 2010, 08:26:08 PMi once bought a pick-up truck and the DMV put a "5" in the VIN instead of an "S"my title did not match my truck boy - that was hard to get fixed
Yes, but it was once. I have this problem with my name several times a day, in several forums.

I have the same problem with the asm programs I try to understand : it seems there are too many letters in them, which I don't know why are there.

Gunner

Actually Sergiu, you look a lot like my CO when I was in the military.....
http://www.facebook.com/photo.php?pid=72908&id=100000283084289
The guy in the bottom left
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

WryBugz


Sergiu FUNIERU

I'm seriously thinking about launching a new website regarding my first name. Of course, I'll buy all the misspellings. :bg



Quote from: WryBugz on February 23, 2010, 10:25:49 PMTry being named Wry.
I'm not talking about mnemonics  :wink
It's first time I heard this name, but it's easier to remember. I mean it.



Quote from: Gunner on February 23, 2010, 10:19:37 PM
Actually Sergiu, you look a lot like my CO when I was in the military.....
http://www.facebook.com/photo.php?pid=72908&id=100000283084289
The guy in the bottom left
It seems that so many people looked at my picture that will be a good idea to post the question on my forehead. I haven't figure out yet how to synchronize the picture with the topic.



My poor includelib question : we left it back in the dust...

dedndave

i think that is a matter of static and dynamic linking, Sergiu
i am not yet that familiar with JWasm, so i'll leave it to those who are

jj2007

Quote from: Sergiu FUNIERU on February 23, 2010, 07:46:57 PM
wlink system nt file index.obj

How did you get rid of Warning! W1107: undefined system name: nt ?

By the way: include c:\masm32\include\windows.inc is a bad habit, since many members have installed Masm32 on another drive. Please use include \masm32\include\windows.inc