News:

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

Simple Static Library

Started by dedndave, November 30, 2010, 01:44:53 AM

Previous topic - Next topic

dedndave

i wanted to make myself a simple static library example
i did so, and it works - see attached (the files need to be in a folder named masm32\examples\static)

but a question came up - and i used to know and understand the answer
i browsed the masm reference manual and came away more confused than before
a sign of old age, i guess

at any rate, maybe someone could explain the difference in simple terms between EXTERN and EXTERNDEF   :P

EDIT - updated file with EXTERNDEF
be sure to place the zip in the \masm32\examples folder so that the destination folder is named \masm32\examples\static

Antariy

Quote from: dedndave on November 30, 2010, 01:44:53 AM
i wanted to make myself a simple static library example
i did so, and it works - see attached (the files need to be in a folder named masm32\examples\static)

but a question came up - and i used to know and understand the answer
i browsed the masm reference manual and came away more confused than before
a sign of old age, i guess

at any rate, maybe someone could explain the difference in simple terms between EXTERN and EXTERNDEF   :P

In simple: differencies is not exist :P

redskull

PUBLIC makes a variable defined in a module visible to all others, and EXTERN declares an external one; essentially, PUBLIC "exports" a symbol and EXTERN imports it.  EXTERNDEF is a convienient way to make it public or extern, depending on whether the symbol is in the module or not.

or, at least, thats the way i understand it (usually wrong)

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

Antariy

Quote from: redskull on November 30, 2010, 01:53:49 AM
or, at least, thats the way i understand it (usually wrong)

In context of export - yes, differencies exist. But Dave asks for differencies while "import" - and then they does not exist.

hutch--

Yep, red has it right. Use EXTERNDEF as it supercedes EXTERN / EXTRN to use a PUBLIC variable from another library module. Use PUBLIC if you want a variable seen by other modules.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

ok - thanks Red
that's what i saw in the manual
i thought there was more to it - my memory isn't what it used to be

public - i got   :U

dedndave

i updated the original post with EXTERNDEF   :bg

japheth

None of the posts so var is truly correct - astonishing!

redskull is close, but it still lacks important information.

EXTERNDEF may do three things, mutually exclusive:

- the symbol becomes public - if it is defined somewhere in the module
- the symbol becomes external - if it is NOT defined, but referenced in the module
- the symbol becomes "nothing" - if it is neither defined nor referenced in the module.

So the EXTERNDEF directive is quite similiar to PROTO. In fact:

<name> PROTO <params>

is just a shortcut for:

EXTERNDEF <name>: PROTO <params>


dedndave

thanks Andreas  :U
in this case, i wanted to use it like i used EXTRN in the old 16-bit days - it seems to work fine

GregL

Dave,

I modified your example slightly to show you how I have used EXTERNDEF.

Note: I uploaded the wrong file, it's right now.

dedndave

so - you just replace all of what we used to use PUBLIC's and EXTERN's for ?

(with the exception that, for PUBLIC, you now have to specify the type)

GregL

Dave,

Yeah, that's basically it.  It does eliminate problems with multiple definitions etc.  I can't remember the exact details but it eliminated a problem like that for me once.

EXTERNDEF

dedndave

thanks Greg  - and the rest of the gang, too   :U

fearless

I have a quick query in relation to making static libraries that someone might be able to answer.

If i have all my functions in one .asm file and its compiled to a single .obj file and then converted to a .lib file, when i link it does the program linking/using it take all the functions over - even ones not used?

Im wondering in relation to this if it would be better to create seperate files for each function, have then compiled to .obj files and converted to one .lib file. Would that be any different? would the program using the .lib take all the code over to use or just functions that are used by the program?
ƒearless

dedndave

as i understand it, each OBJ is a module in the library
if you pull in one part of an OBJ, the entire module is pulled in
it shouldn't be too hard to split the asm file and make seperate OBJ's, though

but - this is easy to test   :P
just declare a 10 Kb static buffer and don't use it
see if it makes the EXE larger
you can do the same in the code section