Using Assembly Language for Intel based Computers - Unresolved externals

Started by micropolisintel, July 02, 2007, 03:18:42 PM

Previous topic - Next topic

micropolisintel

Hi all

I'm attempting to learn Assembly language, and trying to get a development environment working.  I appreciate there are loads of tutorials out there and what I am attempting to do isn't rocket science.  I have a book which I am reading called 'Using Assembly Language for Intel based Computers by Kip Irvine'.   I am using the book because it provides a structured learning approach which I find useful - essential!

The book comes with source code examples, three include files (irvine32.inc Macros.inc SmallWin.inc) and a pre-complied library file (Irvine32.lib) there are also two .asm files (Irvine32.asm and LibTest.asm).

I have copied the include files into the include directory of and the single .lib file into the lib directory, I have also copied all the .asm files into the m32lib directory of MASM32.

I have then run the makelibs.bat in the main MASM32 directory again so that the .asm files are rebuilt.

I HAVE MANAGED TO SUCCESSFULLY BUILD an .obj file.  However when I then attempt to link the file using the 'Project->Assemble and Link' option I get the following errors.

AddSub.obj : error LNK2001: unresolved external symbol _ExitProcess@4
AddSub.obj : error LNK2001: unresolved external symbol _DumpRegs@0
AddSub.exe : fatal error LNK1120: 2 unresolved externals

The project isn't rocket science actually it only adds two number together!!  YEAH THIS IS LAME, BUT I'M JUST STARTING OUT HERE!!!!!  Here is the source code ..... DON'T LAUGH :lol :bg


TITLE Add and Subtract              (AddSub.asm)

; This program adds and subtracts 32-bit integers.
; Last update: 2/1/02

include \masm32\include\Irvine32.inc
.code
main PROC

   mov eax,10000h      ; EAX = 10000h
   add eax,40000h      ; EAX = 50000h
   sub eax,20000h      ; EAX = 30000h
   call DumpRegs

   exit
main ENDP
END main



Could someone advise me on how to resolve this error, obviously there is some adjustment I need to make to the linker, does anyone know what I need to do, basically to get this linking from within quick editor?

MichaelW

In the interest of keeping it simple I would avoid mixing the Irvine components with the MASM32 components. I would just place all of the Irvine components in a separate directory on the same drive as MASM32, create/edit the source using QE or other editor, save the source to the directory, and assemble and link with a batch file like this, also stored in the directory:

\masm32\bin\ml /c /coff micro.asm
pause
\masm32\bin\Link micro.obj irvine32.lib \masm32\lib\kernel32.lib /SUBSYSTEM:CONSOLE
pause
micro
pause

Micro.asm is the name I assigned to your source. I prefer to just modify the batch file for each project, but another possibility is to use a universal batch file that can be run from a command prompt, similar to the batch files that MASM32 uses. And here is a modified version of your source that assembles, links, and runs OK (with the Irvine components that I have):

TITLE Add and Subtract              (AddSub.asm)

; This program adds and subtracts 32-bit integers.
; Last update: 2/1/02

include SmallWin.inc
include Irvine32.inc
.code
main PROC

   mov eax,10000h      ; EAX = 10000h
   add eax,40000h      ; EAX = 50000h
   sub eax,20000h      ; EAX = 30000h
   call DumpRegs

   exit
main ENDP
END main

And here is a listing of the contents of my working directory:

12/27/2005  05:42p               2,614 irvine32.inc
05/13/2005  03:44a               9,760 Macros.inc
05/13/2005  03:45a              13,204 SmallWin.inc
05/04/2005  11:51p              29,780 irvine32.lib
05/05/2005  12:03a                 240 TestLib.asm
05/05/2005  12:01a              32,619 Irvine32.asm
07/02/2007  12:19p                 150 MAKEIT.BAT
07/02/2007  12:18p                 360 micro.asm
07/02/2007  12:50p                 525 micro.obj
07/02/2007  12:50p               7,168 micro.exe
eschew obfuscation

micropolisintel

I really appreciate your advice, thanks, yeah I got it to work!  :U

It's just a shame that I can't select Assemble & Link in QEditor (I'm just a click-click junkie). However I suppose I will only be messing around with Irvine's Assembly Language for Intel-Based Computers until I'm proficient enough to understand what is what.

Thanks again.


"Deception is a state of mind and the mind of the State" - James Jesus Angleton, Head of CIA Counter Intelligence 1954-1974
http://video.google.com/videoplay?docid=786048453686176230&q=terrorstorm&total=795&start=0&num=10&so=0&type=search&plindex=0

ograbme

@MichaelW,

Howdy!  I've read a number of your responses to folks who have tried "mixing" (if you will) irvine32 and MASM32 .inc and .lib.  I've tried (am still trying) to do the same thing myself and have failed ... even though I believe I have followed your very clear and succinct directions to the "t".  But, for me at least, I've had no success thus far.  Then I stumbled across this post where again IMHO I feel you did an excellent job of explaining the potential solution and the gentleman who posted originally his problem had success taking your suggested approach!  My eyes read the listed irvine files you had used and ... in particular the file sizes of the various irvine files.  Low and behold the sizes of irvine32.inc and other files do not match the size of the file sizes I recently downloaded and have been using from Kip's web site ... not by a long shot!  For instance, if I read your posting correctly, your irvine32.inc is a size of 2600+ bytes in size and your irvine32.lib is something like a whopping 29000+ bytes!  Compared to the ones that I downloaded, we ain't even close!  Mine are 6 and 65 KB respectively.  Mind my asking where you got yours?  LOL!  As I said I downloaded mine from his web site ... and obviously something is wrong.

Thanks in advance and keep in mind the above words are just my comments as to what I've been experiencing, but I think I have a better idea why I've had no real success compared to the others!  Keep up the good work and I do get a lot out of what you suggest for others to do.  I just hope I finally have some luck in the near future.  I'll be an old man (heck, I already am) before my time!  Take care.

MichaelW

I don't know for sure where I got them, and now that I check the one's I have are from 2005. If you are still having problems, post your source and I'll see what I can do with it using the new components.
eschew obfuscation

ograbme

Thanks, MichaelW, for your gracious offer - the code I was using is identical to what the original poster posted.  The only difference I can see in my attempt is the size of the  irvine files (.inc, .lib. et al).  I downloaded them from http://kipirvine.com/asm/examples/index.htm.  Note the page states they are the Complete set of examples and link libraries posted on 04/03/2007.  The good majority of them are dated from 2005.  It's the size of these files versus the size of the files you used that caught my attention.  Not sure what the heck the difference in them is, but there is a difference.  I'm going to try to get in touch with Kip (he seems to be willing to help those who want to learn).

I don't think it would be worth your time to do anything as, in fact, you've already done it a few times for other earlier posters.  The only way that I "might" experience success is that I try it using the files you used and, of course, there is no guarantee of success doing that either.  Thanks for your help though.  I was originally attempting to learn this stuff on a Win XP Home Edition SP2 machine using Visual C++ 2005 Express Edition and I got a few of them to work, but ... for some reason Visual C++ Express Edition got flakey on me and would experience problems and shut itself down, soooo ... I thought I would move the irvine code over to a Win 98SE machine and attempt to use Hutch's QE editor.  After experiencing some problems with the code using that IDE (nothing major as I could assemble it, but had the unresolved linker symbol problems), so I started searching this forum to see if others tried the same thing and what problems and solutions they encountered ... that's when I ended up reading a lot of your posts.  As I said before, keep up the good work.  May be soon I will hear back from Microsoft what the heck the Visual C++ Express Edition problem(s) is(are)  and will switch back.  So as to not leave the wrong idea to anyone, I've had success with Hutch's QE Editor with many of the programs folks have contributed to this forum.  IMHO, it's a good tool.

Take care.

VonKyrin

I was looking at the error messages in the original post and I think I know what the problem was.
Here are the original errors:

AddSub.obj : error LNK2001: unresolved external symbol _ExitProcess@4
AddSub.obj : error LNK2001: unresolved external symbol _DumpRegs@0
AddSub.exe : fatal error LNK1120: 2 unresolved externals

I believe ExitProcess is part of the Win32 API, and so you have to include the Win32 API to use it. I believe DumpRegs is part of Irvine32 and is a proc that Kip Irvine wrote, so you have to include that file as well.

In this case, I believe if you just add an "INCLUDE C:\MyFileLocation\SmallWin.inc"into your code it will contain the definitions for DumpReg and I believe it also already has the proper INCLUDE statement for ExitProcess in it as well, so you don't have to include anything specific for ExitProcess.

I've done several examples out of the KipIrvine book, and while the instructions in the book (and on his website) are sometimes not quite enough to get the job done, the examples do seem to all work once you get all the file paths and linker options straightened out.

I believe SmallWin.inc contains most of the Windows definitions you need to run his console app examples and GraphicsWin.inc has the definitions that you need for most of his windowed examples.

With a little bit of "tweaking", I've gotten his examples to compile/assemble using ml.exe and link.exe. I've also modified his examples to complie with ml64.exe. And using the information on his website, I was able to get Visual Studio 2008 Professional to assemble and even debug his examples. I haven't entirely figured out debugging yet though; sometimes I have to start the program, then attach to it's process, and then restart the program in the debugger to get it to give me step debugging and break points.

I've also used windbg.exe to debug the Irvine examples.

I think you probably need proto-type statements (PROTO) for any procedures you call from those include files, although those include files have lots of prototype definitions within them, that I believe save you the trouble of declaring them.


Oh. Also, don't forget to make sure that any INCLUDEs, that you have, actually point to the place where the file actually exists.