1

I've been trying to assemble this codeproject program with Nasm and Crinkler, but every time I try to link the object file with kernel32.lib and user32.lib it gives me the following output:

Crinkler 2.3 (Jul 21 2020) (c) 2005-2020 Aske Simon Christensen & Rune Stubbe

Target: out.exe
Tiny compressor: YES
Tiny import: NO
Subsystem type: WINDOWS
Large address aware: NO
Compression mode: SLOW
Saturate counters: NO
Hash size: 500 MB
Hash tries: 100
Order tries: 0
Reuse mode: OFF (no file specified)
Report: NONE
Transforms: NONE
Replace DLLs: NONE
Fallback DLLs: NONE
Range DLLs: NONE
Exports: NONE

Loading window.obj...
Loading kernel32.lib...
Loading user32.lib...

Linking...

Forced alignment of 1 code hunk to 1 (including entry point).

WINDOW.OBJ: START: error LNK: Cannot find symbol 'GetModuleHandleA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'LoadIconA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'LoadCursorA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'RegisterClassExA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'MessageBoxA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'CreateWindowExA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'ShowWindow'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'UpdateWindow'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'PeekMessageA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'TranslateMessage'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'DispatchMessageA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'ExitProcess'
WINDOW.OBJ: WindowProc: error LNK: Cannot find symbol 'PostQuitMessage'
WINDOW.OBJ: WindowProc: error LNK: Cannot find symbol 'DefWindowProcA'

I've also tried to link it with golink and it gives me the same errors in its format:

GoLink.Exe Version 1.0.3.0  Copyright Jeremy Gordon 2002-2018   info@goprog.com

Error!
The following symbols were not defined in the object file or files:-
ExitProcess
RegisterClassExA
CreateWindowExA
MessageBoxA
GetModuleHandleA
PeekMessageA
TranslateMessage
DispatchMessageA
PostQuitMessage
DefWindowProcA
ShowWindow
UpdateWindow
LoadIconA
LoadCursorA
Output file not made

The command lines are:

nasm window.asm -f win32

crinkler /NODEFAULTLIB /ENTRY:START /SUBSYSTEM:WINDOWS /TINYHEADER window.obj  kernel32.lib user32.lib

golink window.obj kernel32.lib user32.lib

And in the code I have:

extern printf
extern ExitProcess
;all other externs

;more code
START:

push 0
call GetModuleHandleA
;more code

Another weird thing I noticed happens when I remove kernel32.lib and user32.lib on the linker, I get to new errors:

Crinkler import: _Import: error LNK: Cannot find symbol '__imp__MessageBoxA@16'
Crinkler import: _Import: error LNK: Cannot find symbol '__imp__LoadLibraryA@4'

Which is what I would normally expect on failed imports, normally they have "imp" before the name and "@number" after it.

Also, I tried importing win32n.inc and using:

import ExitProcess kernel32.dll

it failed with the nasm output:

error: parser: instruction expected

Any ideas on why it is happening and how to fix it? Thanks.

JeffLee
  • 111
  • 1
  • 10
  • Hmmm... just changed `ExitProcess` to `_ExitProcess@4` and it worked, it seems that I need the names in this kind of strange format (I have to change all of them to see if it works), does anybody know where I can find the names in this format(changing "name" to "_name@4" won't work because the numbers are different between them) – JeffLee Aug 20 '20 at 10:06
  • NVM they are inside kernel32.lib and user32.lib I'm gonna have a great time finding them... – JeffLee Aug 20 '20 at 10:22
  • 1
    See https://stackoverflow.com/questions/18812529/nasm-symbol-at-function-declarations – Michael Aug 20 '20 at 10:37
  • Thanks @Michael, for me it was easier to look inside the lib files, where I could find the number already there, now I know where it comes from too, and knowledge is knowledge. – JeffLee Aug 21 '20 at 08:50

1 Answers1

1

Fixed it!

Just had to replace every extern "name" by an extern _"name"@"number" that I had to obtain by looking at kernel32.lib and user32.lib.

JeffLee
  • 111
  • 1
  • 10
  • Do you mean `extern`? That's the NASM directive, not `external` – Peter Cordes Aug 20 '20 at 18:39
  • I am glad you have got your solution and thanks for your sharing, I would appreciate it if you mark them as answer and this will be beneficial to other community. – Zeus Aug 21 '20 at 03:13
  • @PeterCordes You are right, I've edited my answer, thanks for pointing that out, Every day my memory is worse. – JeffLee Aug 21 '20 at 08:44
  • 1
    @ZhuSong I would mark it as an answer, but StackOverflow has decided that I have to wait two days before you can mark your own answer as correct. Tomorrow I'll do it. – JeffLee Aug 21 '20 at 08:46