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

fearless

Ill try it later tonight see what results i get. Cheers.
ƒearless

BogdanOntanu

Quote from: fearless on December 13, 2010, 10:10:24 AM
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?

NO. The linker will extract from the lib only the functions that are used in your program.
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

dedndave

i just tried it with my static lib example
whether i add an unused 10 kb buffer in the data or code section, the EXE grows
interestingly, it gets slightly larger if it is in the code section - lol
at any rate, it works as i suspected
just ignore bogdan   :lol

Ficko

Quote
just ignore bogdan

Yep, I think too that there is more to it. :bg

I didn't go to the bottom of it but my experience it is heavily linker and switches dependent.

MS Linker links everything to the executable contains in the same asm - obj - file.
In debug mode it even links all the jump tables regardless of you may not use calls through the jump table.

I didn't try the switch to optimize through modules but it may works only for managed assemblies.

jj2007

Hey, let's start a little flaming war :cheekygreen:

\masm32\m32lib\make.bat is an interesting file. Hutch will give us the full story :wink

dedndave

lol - g'mornin Jochen
well - afternoon over there, i suspect

i don't see that Hutch uses any special switches in that BAT file
he does assemble and link from response files, is all
you can view them with notepad

Z sends a K, as always, my friend

Vortex

No any problem with Bogdan's reply. He's correct. It's preferable to move your asm modules to multiple files before building the static library.

dedndave

well Erol - you da man - so i can't argue with you - lol
but, that is not what i am seeing when i add an unnamed, unreferenced 10 Kb buffer to the asm file   :P

Vortex

Hi Dave,

My apologies, I missed your statement about the 10K buffer. Could you please post here your example code?

dedndave

in the archive, you will find three folders, static, static2, static3
place them in masm32\examples
then, run the make batch files...

Vortex

Hi Dave,

Thanks for posting the example code. The result is normal as the buffer sized 10Kb is already included in the source code. My solution is to move the buffer to a separate .asm module :



.386
.model flat,stdcall
option casemap:none

PUBLIC buffer

.data

buffer  db 10240 dup (90h)

END


If you remove the semi-colon ; in the line

; EXTERN      buffer:BYTE

then you get an executable sized more than 10Kb



.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\msvcrt.inc

sum         PROTO :DWORD,:DWORD

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\msvcrt.lib
includelib  testlib.lib

; EXTERN      buffer:BYTE

.data

format1     db '10 + 20 = %d',0

.code

start:

    invoke  sum,10,20

    invoke  crt_printf,ADDR format1,eax
         
    invoke  ExitProcess,0

END start

dedndave

well - that was what i said originally
the question was posted here...

http://www.masm32.com/board/index.php?topic=15480.msg128232#msg128232

i'll chalk it up to bogdan misunderstanding English - a language translation thing
but, i was much happier when he was just wrong   :bdg

Vortex

Hi Dave,

Everything is fine. Static and dynamic libraries are always the friends of programmers.

dedndave

right
it is best to split the asm files, anyways
a nice modular architecture is easier to maintain


...i am working on some library code at the moment
it happens to all be in one file, because the subroutines are all an integral part of the main routine

jj2007

Quote from: Vortex on December 13, 2010, 08:18:55 PM
If you remove the semi-colon ; in the line

; EXTERN      buffer:BYTE

then you get an executable sized more than 10Kb

I guess if you don't remove the semi-colon you can't use the buffer...