News:

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

Main Menu

error LNK2001: unresolved external symbol

Started by jj2007, July 16, 2023, 09:25:19 PM

Previous topic - Next topic

jj2007

include \masm32\include\masm32rt.inc
; we do NOT include \masm32\include\WinSpool.inc
includelib \Masm32\lib\WinSpool.lib ; rarely used, not included in masm32rt

.code
start:
  CreatePrinterIC PROTO STDCALL :DWORD,:DWORD,:DWORD ; one too many but assembles fine
  invoke CreatePrinterIC, 1,2,3 ; but the linker says Unresolved external symbol '_CreatePrinterIC@12'
  exit

end start

So far, so simple. I have often asked myself "how does the linker know xxx needs two args, and not three or five?"

WinSpool.lib is an import library. It redirects requests to the corresponding dll C:\Windows\System32\WinSpool.drv

So, how does the linker know it needs two args? This information is not contained in the DLL (and I consider that a major design flaw).

The answer is that the information was stored in the *.lib file when it was created, using the info given in its *.def file.

Still learning ;-)

mabdelouahab

Quote from: jj2007 on July 16, 2023, 09:25:19 PMThe answer is that the information was stored in the *.lib file when it was created
the information stored is the symbole exported:  _CreatePrinterIC@8

TimoVJL

pFile    Data    Description    Value
0000982C    0000    Sig1    IMAGE_FILE_MACHINE_UNKNOWN
0000982E    FFFF    Sig2    IMPORT_OBJECT_HDR_SIG2
00009830    0000    Version   
00009832    014C    Machine    IMAGE_FILE_MACHINE_I386
00009834    52155509    TimeDateStamp    2013-08-22 00:02:17 UTC
00009838    32    Size Of Data   
0000983C    0028    Hint   
0000983E    000C    Type    IMPORT_OBJECT_CODE
        Name Type    IMPORT_OBJECT_NAME_UNDECORATE
        Symbol info:   
        Symbol Name    _CreatePrinterIC@8
        Dll    _CreatePrinterIC@8
        Name    CreatePrinterIC
May the source be with you

mabdelouahab

Quote from: jj2007 on July 16, 2023, 09:25:19 PMThe answer is that the information was stored in the *.lib file when it was created
the information stored is the symbole exported:  _CreatePrinterIC@8

jj2007

Quote from: mabdelouahab on July 16, 2023, 09:47:45 PM
Quote from: jj2007 on July 16, 2023, 09:25:19 PMThe answer is that the information was stored in the *.lib file when it was created
the information stored is the symbole exported:  _CreatePrinterIC@8

Yes indeed. The point here is that it's not stored in the DLL, but only in the lib file.

zedd151

Quote from: jj2007 on July 16, 2023, 11:25:24 PMYes indeed. The point here is that it's not stored in the DLL, but only in the lib file.
That is strange.
I would think that an include file or a C header was used in generating the .lib file.
Unless you created the .lib file yourself, which would be  a different story. Mileage would vary in that instance.

mineiro

I'd rather be this ambulant metamorphosis than to have that old opinion about everything

zedd151

Quote from: mineiro on July 17, 2023, 12:38:00 AMret8
:biggrin:   You have a good point there, every one else here missed that.   :biggrin:

jj2007

Quote from: zedd151 on July 16, 2023, 11:58:19 PMThat is strange.

I had written a fairly detailed answer to this, zedd. I posted it, but it disappeared. Instead, I see only a cryptic "ret8" post by mineiro. What happened? You are not a moderator here, right? I saw that you moved my initial post from The Lab to the Workshop, and didn't want to comment on that, but if I invest time into a reply, I don't want it to disappear.

zedd151

#9
I have not DELETED any posts.
I moved the Topic from The Laboratory to The Workshop. That is ALL I did.

Such moves are a housekeeping measure, and within my purview as a staff member.

jj2007