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.
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.
Related
So I'm currently trying to call the exported functions of a dll inside my assembly file.
The DLL is in the same directory as my asm program, I don't have the .lib file.
Here is my code:
EXTERN __imp__CreateCompressor#12:PROC
EXTERN __imp__Compress#24:PROC
EXTERN __imp__CloseCompressor#4:PROC
.code
START:
push 2 ;COMPRESS_ALGORITHM_MSZIP
push 0
push OFFSET hCompress
call __imp__CreateCompressor#12
push 0 ;CompressedDataSize
push DWORD ptr [DataSize] ;CompressedBufferSize
push eax ;CompressedBuffer
push DWORD ptr [DataSize]
push DWORD ptr [pBuf3]
push DWORD ptr [hCompress]
call __imp__Compress#24
push DWORD ptr [hCompress]
call __imp__CloseCompressor#4
END START
However I get the errors:
file.obj : error LNK2001: unresolved external symbol ___imp__CreateCompressor#12
file.obj : error LNK2001: unresolved external symbol ___imp__Compress#24
file.obj : error LNK2001: unresolved external symbol ___imp__CloseCompressor#4
file.exe : fatal error LNK1120: 3 unresolved externals
I'm assembling it like so:
ml file.asm /link /subsystem:console /entry:START
Any ideas?
You must use LoadLibrary() and GetProcAddress() functions to load the library and get the address from the function you want to call.
To enable Load-Time Dynamic Linking the linker needs an import library.
Without an import library you're going to have to use Run-Time Dynamic Linking.
Alternatively, you can generate an import library yourself. The easiest way to do so is to author an appropriate Module-Definition (.Def) File and have the Microsoft Librarian Manager (LIB.exe) generate an import library.
.386
.model flat, c
.stack 100 h
.data
num1 sdword ?
num2 sdword ?
.code
main proc
mov num1,5
mov eax,num1
mov num2,eax
ret
main endp
end
I have checked the masm in the build customization of the project.
I have changed the item type to Microsoft Macro Assembler.
But, it is still showing error messages below:
Severity Code Description Project File Line Suppression State
Error A2206 missing operator in expression testing C:\Users\Kin\Desktop\assembly\testing\testing\Source.asm 3
Error A2206 missing operator in expression testing C:\Users\Kin\Desktop\assembly\testing\testing\Source.asm 2
Error MSB3721 The command "ml.exe /c /nologo /Zi /Fo"Debug\Source.obj" /W3 /errorReport:prompt /TaSource.asm" exited with code 1. testing H:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\BuildCustomizations\masm.targets 50
Changed to .stack 100h
It is now showing:
Severity Code Description Project File Line Suppression State
Error LNK1120 1 unresolved externals testing C:\Users\Kin\Desktop\assembly\testing\Debug\testing.exe 1
Error LNK2001 unresolved external symbol _WinMainCRTStartup testing C:\Users\Kin\Desktop\assembly\testing\testing\LINK 1
I'm trying to run an assembly program using MASM in Visual Studio. This is the code I have
include Irvine32.inc
.data
str1 BYTE "a test string",0
.code
main proc
mov edx,OFFSET str1
call WriteString
exit
main endp
End main
The error I'm getting is:
error LNK2019: unresolved external symbol _WriteString#0 referenced in function _main#0"
Why am I getting this error?
Press Shift + Alt + A
find Irvine32.inc and Irvine32.lib from your HDD
Add them in your project repository.
The linker error suggests that you aren't linking against the Irvine32 library. Although you have included Irvine32.inc at the top of your assembly program, you still need to add Irvine32.lib as a library to link against in your Solution, or add it to your command line (if compiling with at a command shell), or use includelib directive inside your assembly code to link with it.
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
DumpRegs PROTO
.code
main proc
mov cx, 01h
sub cx, 2
call DumpRegs
add cx, 2 ; Clears the sign flag
invoke ExitProcess,0
main endp
end main
Errors:
1>Example.obj : warning LNK4258: directive '/ENTRY:main#0' not compatible with switch '/ENTRY:main'; ignored
1>Example.obj : error LNK2019: unresolved external symbol _DumpRegs#0 referenced in function _main#0
1>C:...: fatal error LNK1120: 1 unresolved externals
I tried looking up how to resolve this issue but have had no luck. Can anyone help me get this thing running?
SOLUTION: For those using Kip Irvine's book and trying to get their stuff to work, you can find how to create a project from scratch using the libraries in his book here (bottom): http://kipirvine.com/asm/gettingStartedVS2013/index.htm
Note that it is below his first two entrys on how to create a program which makes it somewhat difficult to find.
you need to include the library that has the dumpregs process using INCLUDE and INCLUDELIB.
I have a problem with SAPI: While I am compiling some code, I encounter this error in CodeBlocks:
||Warning: .drectve `/DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"uuid.lib" ' unrecognized|
obj\Debug\main.o||In function `main':|
C:\Documents and Settings\Mert\Desktop\yazi\okuproje\main.c|11|undefined reference to `CoInitialize#4'|
C:\Documents and Settings\Mert\Desktop\yazi\okuproje\main.c|14|undefined reference to `CoCreateInstance#20'|
C:\Documents and Settings\Mert\Desktop\yazi\okuproje\main.c|29|undefined reference to `CoUninitialize#0'|
||=== Build finished: 3 errors, 1 warnings ===|
My Code: http://pastebin.com/LCpCns2p
You don't mention which compiler you're using with CodeBlocks (or, more importantly, which linker), however, the errors you're getting are caused by missing libraries.
You'll need to add a reference to uuid.lib (to get the GUID definitions for IID_ISpVoice), and ole32.lib (to get the definitions for CoInitialize, CoCreateInstance, and CoUninitialize).