News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

[SOLVED] Issue While Working On My Homework (LNK2001 Error)

Started by kennyd8200, September 06, 2020, 07:47:11 AM

Previous topic - Next topic

kennyd8200

So I am new to the programming world, I started a class on microprocessors this semester and our first lab is using Visual Studio to create an Assembly file to add two numbers. I have followed the instructions completely and keep coming up with error code LNK2001 unresolved external symbol _MAIN   LINK  Line 1, followed by LNK1120. I had a Zoom meeting with my professor today and he can't even understand the problem with it. If anyone can help, please go into as much detail as possible as I am pretty much illiterate when it comes to coding. This is what I'm working with.

.MODEL  FLAT
.DATA
.CODE

main   PROC
      ;----- CLEAR CONTENTS OF REGISTERS -----
      xor eax,eax
      xor ebx,ebx
      xor ecx,ecx
      xor edx,edx
      ;----- BEGIN MAIN PROCEDURE HERE -----

      mov  ax,5
      add  ax,3

      ;----- END MAIL PROCEDURE HERE -----
      ret
main   ENDP

END

fearless

I would add stdcall to the model directive and precede with a processor directive .386 as an example, and end with the end pointing to the main proc
.386
.MODEL FLAT, STDCALL
.DATA
.CODE

main PROC
      ;----- CLEAR CONTENTS OF REGISTERS -----
      xor eax,eax
      xor ebx,ebx
      xor ecx,ecx
      xor edx,edx
      ;----- BEGIN MAIN PROCEDURE HERE -----

      mov  ax,5
      add  ax,3

      ;----- END MAIL PROCEDURE HERE -----
      ret
main ENDP

END main

kennyd8200

You sir, are a life saver. I used all parts that you suggested and got a success notification, did a little edit and found out that stdcall was the only necessary addition. Thank you for your help!

mineiro

hello sir kennyd8200;
END
When you code this way (remove that line or comment), you're doing a module that will be added (agregate) to other modules to form final executable or a library (like dll files or .lib files), well, read object files that will be joined to final executable file.
You need specify where your program will start, the address (entry point) of your program by adding a label (memory address) to that as fearless point you.
Please, next time post your command line too, will be more easy to help you. Assembler (linker) have an option to you specify what's the entry point of your program in command line instead of being in code.
Windows adopt some rules to programs runs fine in it, this means that we need follow rules to our program runs in windows, and better, others can call our "modules" if they follow rules. Thats the "stdcall".
Good lucky man, keep walking.

---edited--- linker, (remove that line or comment)
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

deeR44


Zeroing the registers does nothing useful.

I can't imagine what you mean by "Begin a Mail Procedure." I worked for the Postal Service for thirty years and never once began a "mail procedure." And I was a Systems Analyst.

hutch--