The MASM Forum

General => The Campus => Topic started by: filipmr on May 08, 2021, 02:29:44 AM

Title: I get a few errors, including Hello.obj : error LNK2001: unresolved external sym
Post by: filipmr on May 08, 2021, 02:29:44 AM
I am a beginner in assembly. I install masm32..... Getting the .obj file worked perfectly, but when I tried to link it(turn it into .exe file) I got 4 errors. This is my code:.386

.model flat,stdcall

option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc

includelib \masm32\include\kernel32.lib
includelib \masm32\include\masm32.lib
.data
HelloWorld db "Hello World!",0
.code
start:
invoke StdOut, addr HelloWorld
invoke ExitProcess,0
end start



, and here are the errors that I got: `

Hello.obj : warning LNK4033: converting object format from OMF to COFF

Hello.obj : error LNK2001: unresolved external symbol _StdOut@4

Hello.obj : error LNK2001: unresolved external symbol _ExitProcess@4

LINK : error LNK2001: unresolved external symbol _mainCRTStartup

Hello.exe : fatal error LNK1120: 3 unresolved externals
I really don't know what could be the problem, can someone help?
Title: Re: I get a few errors, including Hello.obj : error LNK2001: unresolved external sym
Post by: avcaballero on May 08, 2021, 02:47:30 AM
Very close to my code. Maybe it losts on paths.

.386
.MODEL     flat, stdcall
OPTION     casemap :none
         
INCLUDE    windows.inc
INCLUDE    kernel32.inc
INCLUDE    masm32.inc
         
INCLUDELIB kernel32.lib
INCLUDELIB masm32.lib
         
.DATA
  msg   DB "Hola mundo, en consola windows.", 0

.CODE
start:
  INVOKE     StdOut, ADDR msg
  INVOKE     ExitProcess, 0

END start


Complile with

C:\masm32\bin\ml.exe /c /coff /Cp /IC:\masm32\Include ConWM01.ASM
C:\masm32\bin\link.exe /SUBSYSTEM:CONSOLE /LIBPATH:c:\masm32\lib ConWM01.obj


It works to me  :biggrin:
Title: Re: I get a few errors, including Hello.obj : error LNK2001: unresolved external sym
Post by: filipmr on May 08, 2021, 02:49:03 AM
Thank you a lot, I will try that.....
Title: Re: I get a few errors, including Hello.obj : error LNK2001: unresolved external sym
Post by: filipmr on May 08, 2021, 02:52:12 AM
I still get the same errors.....
Title: Re: I get a few errors, including Hello.obj : error LNK2001: unresolved external sym
Post by: HSE on May 08, 2021, 02:52:50 AM
To see if is working:

- Open qeditor.exe (is in \masm32 )

- Open your file

- replace options and includes with:
      include \masm32\include\masm32rt.inc

- in the menu Project > Console Assemble & link

:thumbsup:


includelib \masm32\include\kernel32.lib
includelib \masm32\include\masm32.lib

must be:

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
Title: Re: I get a few errors, including Hello.obj : error LNK2001: unresolved external sym
Post by: filipmr on May 08, 2021, 03:31:42 AM
I still get the same errors.....
Title: Re: I get a few errors, including Hello.obj : error LNK2001: unresolved external sym
Post by: jj2007 on May 08, 2021, 04:04:16 AM
As HSE already wrote, includelib must point to the lib, not the include folder. Even better: use masm32rt.inc as shown below (in case you are curious why, open it in Notepad and have a look).

include \masm32\include\masm32rt.inc

.data
HelloWorld db "Hello World!", 0

.code
start:
invoke StdOut, addr HelloWorld
invoke ExitProcess,0
end start
Title: Re: I get a few errors, including Hello.obj : error LNK2001: unresolved external sym
Post by: filipmr on May 09, 2021, 03:08:47 AM
I tried that, but the same thing happened, same 3 errors.....
Title: Re: I get a few errors, including Hello.obj : error LNK2001: unresolved external sym
Post by: HSE on May 09, 2021, 03:16:19 AM
Is your file in same unit that masm32?

Try to build code in \masm32\examples  (with Projects > Buil All if there is not .bat)
Title: Re: I get a few errors, including Hello.obj : error LNK2001: unresolved external sym
Post by: filipmr on May 09, 2021, 09:48:42 PM
I tried moving it to the same dir, the same thing happened.....
Title: Re: I get a few errors, including Hello.obj : error LNK2001: unresolved external sym
Post by: jj2007 on May 09, 2021, 10:46:25 PM
Please run the attachment and post the result here.
Title: Re: I get a few errors, including Hello.obj : error LNK2001: unresolved external sym
Post by: hutch-- on May 09, 2021, 11:32:45 PM
Delete your exist installation and re-install the masm32 SDK. Try not to install it on drive C: as the OS may interfere.

Once it is installed, try one of the samples in the examples directory. Unless you have changed something OR something is broken in your computer setup, it should be able to build any of the examples.