NO

Author Topic: Question about ASM and polink  (Read 6787 times)

GTN

  • Guest
Question about ASM and polink
« on: December 01, 2004, 02:19:55 PM »
Hi !
I've made an ASM file, compiled it to .obj with FASM, until that everything's ok, but when i try to make an exe from the obj file with polink, i get : "Unresolved external symbol "__mainCRTStartup"
Do you know how i could resolve that ?
The main is : _WinMain@16: and is declared as public

thanks !

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Question about ASM and polink
« Reply #1 on: December 01, 2004, 02:55:56 PM »
Hello,

The default entry point depends on the selected subsystem (windows, console...) but is (of course) targeted at Pelles C.

You can can use the option /entry:symbol to change the entry point. In your case, something like /entry:_WinMain@16...

Pelle
/Pelle

GTN

  • Guest
Question about ASM and polink
« Reply #2 on: December 01, 2004, 03:09:35 PM »
Thanks for the reply !
It's a windows program, do i have to add something to the asm code to don't have to put /entry:... each time i compile ?
Anyway i can do that since it's working !!
Thanks again !!

GTN

  • Guest
Question about ASM and polink
« Reply #3 on: December 01, 2004, 03:14:28 PM »
In fact i've found a problem with using this method: It opens a console, but it's not a console app, what can i do to don't show this console ?

Thanks !!
GTN

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Question about ASM and polink
« Reply #4 on: December 01, 2004, 06:36:54 PM »
Quote from: "GTN"
Thanks for the reply !
It's a windows program, do i have to add something to the asm code to don't have to put /entry:... each time i compile ?

From C, you can use this pragma:
#pragma comment(linker, "/entry:_WinMain@16")

From assembler you can put directives in a section called .drectve:
db " -entry:_WinMain@16"
db " -defaultlib:mylib.lib"

(The exact syntax depends on your assembler, which I don't know well enough.)

Quote from: "GTN"
In fact i've found a problem with using this method: It opens a console, but it's not a console app, what can i do to don't show this console ?
GTN

You must specify the correct subsystem to the linker: /subsystem:windows. Default in most cases is: /subsystem:console.

Pelle
/Pelle

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Question about ASM and polink
« Reply #5 on: December 01, 2004, 10:09:42 PM »
Hi GTN,

Here is a simple FASM Ms Coff sample for you:
Code: [Select]

format MS COFF

public start

Include '%fasminc%\win32a.inc'

extrn '__imp__ExitProcess@4' as ExitProcess:dword
extrn '__imp__MessageBoxA@16' as MessageBox:dword

section '.data' data readable writeable

caption db 'Hello',0
message db 'This is a FASM example',0

section '.code' code readable executable

start:

invoke MessageBox,0,message,caption,MB_OK
invoke ExitProcess,0


Building the executable:
Code: [Select]

set fasminc=\fasmw\include
call povars32.bat
fasm Msgbox.asm
polink /SUBSYSTEM:WINDOWS /ENTRY:start Msgbox.obj kernel32.lib user32.lib
Code it... That's all...

GTN

  • Guest
Question about ASM and polink
« Reply #6 on: December 02, 2004, 05:52:53 PM »
Hi !
Thanks for all, it works !!

GTN

tommy

  • Guest
Question about ASM and polink
« Reply #7 on: December 23, 2004, 11:29:33 AM »
Hi!

Earlier I've been able to use FASM with Pelles C to compile assembly files to MS COFF objects, but when I try now, the following command line is produced - which is not the one to use with FASM! I tried to set the ASFLAGS to the files I wanted to assemble etc., but these two arguments are automatically appended anyway... :roll:

Code: [Select]
fasm.exe -Fo"<...>\output\<...>.obj" "<...>\<...>.asm"
<...> = path and file name

Is there a work-around or could you fix this Pelle?? Thanks! (I'm quite sure it worked just a few months ago, is it something with the newest releases? Or am I lost :S :D)

Regards,
Tommy

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Question about ASM and polink
« Reply #8 on: December 23, 2004, 08:43:15 PM »
Hello,

The following command string is currently used for *all* assemblers:
$(AS) $(ASFLAGS) -Fo"$@" "$!"

you can tune the AS and ASFLAGS macros, but -Fo is always there. AFAIK it has always been like this. In my experience, most compilers/assemblers/translators disagree about command line options, but most of them agrees on a -Fo (or /Fo) option. I guess I should add a way of specifying the entire command line for external assemblers (putting -Fo in ASFLAGS isn't very nice).

Now the work-around: change to target view in the project window (click target files button), right-click on the object file, and select Properties from the menu - now you should see the build command(s). Change it to something that FASM likes... ;)

Pelle
/Pelle

tommy

  • Guest
Question about ASM and polink
« Reply #9 on: December 23, 2004, 09:26:55 PM »
:D Thanks!