I'm trying to create a very small and simple library in ASM. This is just a learning exercise so please don't ask me why :biggrin:. I've been throught the process of creating the library and then calling it from the other ASM program but I can't seem to get past identifying the process in the calling program. No matter what I've done, I always get "unresolved external symbol". I need two things:
1. Simple instructions on creating the library and using it in a calling ASM program.
2. A way to view the available procedures in a .lib file. I've tried dumpbin with no luck.
The code in the library(StaticLib03):
.386 ; force 32 bit code
.model flat, stdcall ; memory model & calling convention
option casemap :none ; case sensitive
.code
testproc proc
mov eax, 1
inc eax
ret
testproc endp
end
The code in my calling program(TestLib):
.386
.model flat, stdcall
.stack 4096
ExitProcess proto, dwExitCode:dword
INCLUDE StaticLib03.inc
INCLUDELIB StaticLib03.lib
.data
.code
main proc
call testproc
invoke ExitProcess, 0
main endp
end main
Hi riversr54,
Here is a quick example.
include \masm32\include\masm32rt.inc
sum PROTO :DWORD,:DWORD
mult PROTO :DWORD,:DWORD
.data
string db '%u',13,10,'%u',0
.data?
var dd ?
.code
start:
invoke sum,10,20
mov var,eax
invoke mult,30,40
invoke crt_printf,ADDR string,var,eax
invoke ExitProcess,0
END start
Thanks for the example. I do have a couple follow up questions.
I don't see anywhere that you included any reference to the library file. Is it enough that it just be in the same folder and the linker will find it using the procedure names?
Do you know a way to list procedures in the library?
Thanks very much.
Hello,
sum PROTO :DWORD,:DWORD
mult PROTO :DWORD,:DWORD
The function prototypes are declaring the external functions. The linker will find and extract the procedures examining the static library.
\masm32\bin\polink /SUBSYSTEM:CONSOLE Test.obj testlib.lib
The static library could be located in another folder :
\masm32\bin\polink /SUBSYSTEM:CONSOLE Test.obj D:\libraries\testlib.lib
Listing the procedures :
\masm32\bin\polib.exe /list testlib.lib
mult.obj
sum.obj
You can also use the MS linker to list the procedures :
\masm32\bin\link.exe -lib -list testlib.lib
Microsoft (R) Library Manager Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
sum.obj
mult.obj
Thank you very much. Part of my problem was that I've been trying to do some of this in Visual Studio. I think I'm learning quickly that it may not be the best way.