flat assembler
Message board for the users of flat assembler.

Index > Windows > How to use linker

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
habran



Joined: 31 Aug 2008
Posts: 82
Location: South Australia
habran
Hi strap89,
I tried to compile fasm\examples\mscoff\mscoff.asm and I can create 'obj' but when I try to link it I have link error:
mscoff.obj : error LNK2001 : unresolved external symbol __imp__MessageBoxA@16
LINK : error LNK2001 : unresolved external symbol __WinMainCRTStartup

I have red the fasm manual but there is no info how to link a coff object

what am I doing wrong?

regards
Post 26 Feb 2009, 21:54
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
mscoff.obj : error LNK2001 : unresolved external symbol __imp__MessageBoxA@16

You are calling function "MessageBox" from USER32.DLL. For that, you need to link with USER32.LIB file (and usually also KERNEL32.LIB, and other depending on which Win API procs you call). You can find KERNEL32.LIB, USER32.LIB, and others in basically any compiler package, usually MS Visual Studio, Windows Driver Development Kit, or MASM32.

Quote:
LINK : error LNK2001 : unresolved external symbol __WinMainCRTStartup

Microsoft linker by default expects that you are using standard C library (C Runtime, CRT). Because of that, it will look for .LIB file(s) of that library, and also set entry point of your application to that library, where it is called "_WinMainCRTStartup". You can override this behavior by giving "/NODEFAULTLIB" switch to linker.

You may also need to provide "/SUBSYSTEM:WINDOWS" or "/SUBSYSTEM:CONSOLE" switch to compile your app.
Post 26 Feb 2009, 22:28
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
habran



Joined: 31 Aug 2008
Posts: 82
Location: South Australia
habran
It solved "MesageBox" error but not "WinMainCRTStartup"

here are code for make.bat:





Code:
@echo off


\fasm\fasm -s mscoff.fas mscoff.asm mscoff.o
if errorlevel 1 goto errasm

pecvt mscoff.fas mscoff.obj
if errorlevel 1 goto errpecvt

\masm32\BIN\Link.exe  /SUBSYSTEM:WINDOWS /DEBUG /DEBUGTYPE:CV /VERSION:1.0 /INCREMENTAL:YES /NODEFAULTLIB  \Masm32\Lib\USER32.LIB mscoff.obj
if errorlevel 1 goto errlink


goto TheEnd

:errlink
echo _
echo Link error
goto TheEnd

:errasm
echo _
echo Assembly Error
goto TheEnd

:errpecvt
echo _
echo pecvt Error
goto TheEnd

:TheEnd
dir mscoff.*

pause
    


what is wrong with it?

regards

_________________
down under
Post 27 Feb 2009, 02:54
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 713
Location: Adelaide
sinsi
Try adding "/ENTRY:start" to the link command line (replace "start" with your entry point's label).
Post 27 Feb 2009, 02:59
View user's profile Send private message Reply with quote
habran



Joined: 31 Aug 2008
Posts: 82
Location: South Australia
habran
Thank sinsi, I tried but than I got error :
LINK : error LNK2001 : unresolved external symbol "_start"

I would like to find a solution for that because I don't believe that Tomasz Grysztar has created the coff format just for fan

If someone ever programmed with fasm coff format please help

regards

_________________
down under
Post 27 Feb 2009, 10:54
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
habran wrote:
LINK : error LNK2001 : unresolved external symbol "_start"
The linker is looking for a label named "_start". So you can do this in your asm file:
Code:
format coff ...
entry _start
public _start

_start:
   ;your code starts here
   invoke ExitProcess,0    
Post 27 Feb 2009, 11:07
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Oh yes, I forgot to mention you that when you disable default entry point with /NODEFAULTLIB, you also need to provide another entry point.
Post 27 Feb 2009, 12:45
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
habran



Joined: 31 Aug 2008
Posts: 82
Location: South Australia
habran
Thanks revolution,

now I have assembler error :
entry _start
error: illegal instruction
Post 27 Feb 2009, 12:51
View user's profile Send private message Reply with quote
habran



Joined: 31 Aug 2008
Posts: 82
Location: South Australia
habran
Thanks vid,
LINK : error LNK2001 : unresolved external symbol "_start"
Post 27 Feb 2009, 13:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
habran wrote:
Thanks revolution,

now I have assembler error :
entry _start
error: illegal instruction
Just remove the line. I got confused with the PE format. But you have to use sinsi's suggestion "/ENTRY:start" in the command line.
Post 27 Feb 2009, 13:34
View user's profile Send private message Visit poster's website Reply with quote
habran



Joined: 31 Aug 2008
Posts: 82
Location: South Australia
habran
Still the same error:
LINK : error LNK2001 : unresolved external symbol "_start"

_________________
down under
Post 27 Feb 2009, 21:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
habran: I think it is time to post your fasm code. Else this might just keep going around in circles.
Post 27 Feb 2009, 22:04
View user's profile Send private message Visit poster's website Reply with quote
habran



Joined: 31 Aug 2008
Posts: 82
Location: South Australia
habran
revolution here are the code:


Description:
Download
Filename: MSCOFF.zip
Filesize: 26.26 KB
Downloaded: 229 Time(s)


_________________
down under
Post 27 Feb 2009, 22:13
View user's profile Send private message Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 245
Location: US
Yardman
[ Post removed by author. ]


Last edited by Yardman on 04 Apr 2012, 03:26; edited 1 time in total
Post 28 Feb 2009, 05:03
View user's profile Send private message Reply with quote
habran



Joined: 31 Aug 2008
Posts: 82
Location: South Australia
habran
Yardman, I have got the same result as before
I have no problem to link masm objects, I just want to see any fasm coff objects linked into exe

now I have doubts that it is possible at all to do that

I wish someone prove me wrong

regards
Post 28 Feb 2009, 05:31
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
habran wrote:
Code:
...
\fasm\fasm -s mscoff.fas mscoff.asm mscoff.o
...
pecvt mscoff.fas mscoff.obj
...    
Are you trying to make the .fas file into a .obj file?
Post 28 Feb 2009, 05:36
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 713
Location: Adelaide
sinsi
All I did was change "start" to "_start" in 2 places in your .asm file.
Code:
C:\Users\me\Desktop\MSCOFF>\fasm\fasm MSCOFF.ASM
flat assembler  version 1.67.34  (961348 kilobytes memory)
3 passes, 277 bytes.

C:\Users\me\Desktop\MSCOFF>link /subsystem:windows,4.0 /entry:start MSCOFF.OBJ \masm32\lib\user32.lib
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


C:\Users\me\Desktop\MSCOFF>dir
 Volume in drive C has no label.
 Volume Serial Number is 0FA6-3849

 Directory of C:\Users\me\Desktop\MSCOFF

28/02/2009  05:28 PM    <DIR>          .
28/02/2009  05:28 PM    <DIR>          ..
27/02/2009  11:32 PM               571 makeit.bat
28/02/2009  05:27 PM               374 MSCOFF.ASM
28/02/2009  05:28 PM            16,384 MSCOFF.exe
28/02/2009  05:28 PM               277 MSCOFF.OBJ
27/02/2009  08:33 AM               925 MSCOFF.wap
15/02/2009  04:48 PM            69,632 pecvt.exe
               6 File(s)         88,163 bytes
               2 Dir(s)  153,521,668,096 bytes free

C:\Users\me\Desktop\MSCOFF>
    

Why do you use "pecvt"? There's no need afaict.
Post 28 Feb 2009, 07:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
sinsi wrote:
All I did was change "start" to "_start" in 2 places in your .asm file.
Why doesn't the fasm board have an icon to show disappointment?
Post 28 Feb 2009, 09:59
View user's profile Send private message Visit poster's website Reply with quote
habran



Joined: 31 Aug 2008
Posts: 82
Location: South Australia
habran
Thanks everyone, I am happy that all of you got involved with this issue,
my goal was to test strap89's "pecvt" to create .obj file from .fas file first and then with linker create .pdb file for debugging with WinDbg, but unfortunately .obj file created this way is 'corrupted' so that linker can't create neither .pdb nor .exe, so if I link .o instead of .obj than it makes .exe and .pdb file but WinDbg doesn't have information about line numbers and can not debug source code

conclusion: pecvt doesn't create proper .obj file
I wish that someone can prove me wrong

regards

_________________
down under
Post 28 Feb 2009, 10:58
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
conclusion: pecvt doesn't create proper .obj file
I wish that someone can prove me wrong

I quess it would be helpful for strap89 to upload the .obj file, so he can check whether it is really a problem in his tool, or your error.
Post 28 Feb 2009, 13:31
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.