News:

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

INCLUDELIB in Src File

Started by msqweasm, May 31, 2011, 11:46:31 AM

Previous topic - Next topic

msqweasm

Why we need to specify the library filenames (probably full path to it) using INCLUDELIB inside the source files?  Isn't it a better option to specify them in the command line of the linker?  Just like in C src fiiles, we only include the headers without specifying the library file names.

drizz

You don't need to.

I personally use win32inc + radasm
I created template files for radasm that specifically use a special file for additional linker commands such as libraries.

Example:
template linker cmd file
[*BEGINTXT*]
cmd.linker
/nologo
/INCREMENTAL:NO
/FILEALIGN:512
/VERSION:4.0
/SUBSYSTEM:CONSOLE
kernel32.lib
comctl32.lib
user32.lib
gdi32.lib
comdlg32.lib
shell32.lib
winmm.lib
libc.lib
[*ENDTXT*]


link option line:

...

3=5,OT,$B\LINK.EXE @cmd.linker /RELEASE /LIBPATH:"$L",3

...


radasm path system:
[Paths]
$A=D:\Dev\Masm
$B=$A\Bin
$D=$R\AddIns
$H=$A\Help
$I=$A\Include
$L=$A\Lib" /LIBPATH:"D:\PSDK\Lib" /LIBPATH:"D:\MSVCT\Lib
$P=D:\Dev\Projects\Masm
;;;;;;;;;;;;;;;;;;;;;;;;; a little workaround is needed for libpath


source file sample:
.686
.model flat,stdcall
option casemap:none
include <windows.inc>;  --------- same names as in C
include <stdio.inc>     ;

.data
strHelloWorld db "Hello World",0

.code
main proc C uses esi edi ebx argc:sdword,argv:ptr LPCSTR
invoke printf,addr strHelloWorld
invoke getchar
xor eax,eax
ret
main endp

end



The truth cannot be learned ... it can only be recognized.

msqweasm

Just for the purpose of learning, I want to clarify what they are for.  Are INCLUDELIB and linker parameters  just 2 different ways for doing the same thing?

drizz

well not quite, includelib creates directives in compiled (.obj) files.
So if you put:
includelib mylib.lib
it creates ".drectve" sectiion with the following content:
"-defaultlib:mylib.lib"
hence, specifying full paths is bad if you want to share your code as a compiled static library.
includelib Z:only\on\my\hdd\mylib.lib
"-defaultlib:Z:only\on\my\hdd\mylib.lib"

The user will have to override this with "-nodefaultlib"

C (MS VS) equivalent of includelib is:
#pragma comment(lib, "mylib.lib")

The truth cannot be learned ... it can only be recognized.

dedndave

the linker also looks at the LIB environment variable for a default library file location
this can be overridden by specifying a path on the command line or in the INCLUDELIB directive

the masm32 package is not set up to use this environment variable
apparently, too many people were unable to set the value   :lol
so, Hutch hard-wired the paths
he wanted the package to be easy to install and use

if it had been me, my rule would have been...
"if you can't set an environment variable (or if you don't know what it is), your programming language is BASIC"   :P

another way to go might have been to put the INCLUDELIB directive into the associated INC file
that would cause problems for those who do not have things set up the same way, but it would be easy