Author Topic: ALINK: error AL1047  (Read 10389 times)

Offline net2012

  • Jr. Member
  • *
  • Posts: 4
ALINK: error AL1047
« on: September 01, 2012, 01:59:41 AM »
I'm running Windows7 64 bit. I tried to turn the following two programs into .exe files with al.exe and I got the following error message.

C:\nasm>al filename.obj /target:exe /out:filename.exe /main:entry point
Microsoft (R) Assembly Linker version 9.0.30729.1
Copyright (C) Microsoft Corporation. All rights reserved.

ALINK: error AL1047: Error importing file 'path\filename' -- An
        attempt was made to load a program with an incorrect format.

Here is the code.

Code: [Select]
global _main

extern GetStdHandle
extern WriteFile
extern ExitProcess

section .text
_main:
mov rcx, -11
call GetStdHandle

mov rcx, rax
mov rdx, message
mov r8, (message_end - message)
mov r9, BytesWritten
mov qword [rsp+8*4], 0
call WriteFile

mov rcx, 0
call ExitProcess

;variables
BytesWritten: dq 0
message: db "Hello world"
message_end:

and here is the other one.

Code: [Select]
global _start
extern _MessageBoxA@16
extern _ExitProcess@4
section code use32 class=code
_start:
push dword 0
push dword title
push dword banner
push dword 0
call _MessageBoxA@16
push dword 0
call _ExitProcess@4
section data use32 class=data
banner: db 'Hello, world!', 0
title: db 'Hello', 0

Solutions anyone?

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: ALINK: error AL1047
« Reply #1 on: September 01, 2012, 02:22:54 AM »
I'm pretty certain that Alink does not understand 64-bit object files.  I use Jeremy Gordon's free GoLink tool for writing both 32-bit and 64-bit executables:  http://www.godevtool.com/

Offline net2012

  • Jr. Member
  • *
  • Posts: 4
Re: ALINK: error AL1047
« Reply #2 on: September 01, 2012, 03:22:40 AM »
I just tried adding Golink to my path all of the following ways and it still isn't being recognized at the command prompt when I type 'Golink filename.obj'.

1.     C:\Golink
2.     C:\Golink;
3.     C:\Golink\Golink.exe
4.     C:\Golink\Golink.exe;

None of those will work.

Offline net2012

  • Jr. Member
  • *
  • Posts: 4
Re: ALINK: error AL1047
« Reply #3 on: September 01, 2012, 03:28:53 AM »
I copied the contents of the Golink folder into the nasm folder, then I got the following error after trying to make an exectutable.

C:\nasm>Golink filename.obj

GoLink.Exe Version 0.27.0.0 - Copyright Jeremy Gordon 2002/12 - JG@JGnet.co.uk

Error!
Could not open an input file (filename.obj)
Output file not made

Offline net2012

  • Jr. Member
  • *
  • Posts: 4
Re: ALINK: error AL1047
« Reply #4 on: September 01, 2012, 03:39:25 AM »
Silly me, I deleted the obj file. I have to remake it. LOL.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: ALINK: error AL1047
« Reply #5 on: September 01, 2012, 02:59:09 PM »
I'm confused, net2012. You show two examples, one of which is 64-bit code - I ASSume you assembled it as "-f win64" - and the other is 32-bit code which looks like it's intended to be assembled as "-f obj", but might work as "-f win32" as well...

Then, you attempt to link one or the other or both...
Quote
C:\nasm>al filename.obj /target:exe /out:filename.exe /main:entry point
Microsoft (R) Assembly Linker version 9.0.30729.1
Copyright (C) Microsoft Corporation. All rights reserved.

ALINK: error AL1047: Error importing file 'path\filename' -- An
        attempt was made to load a program with an incorrect format.

Now... I'm familiar with a product I know as "Alink", written by Anthony Williams (quite some time ago!), but this isn't it! I'm not sure which "Alink" Rob had in mind. The "Alink" I know definitely won't do 64-bit files, but I think it "should" handle the 32-bit example you show. I have no idea what format the Microsoft product is looking for!

Apparently you've got GoLink working (both examples?), which may be a better bet, but I'm still curious what (if anything) we can tell Nasm to make it produce something that "al.exe" will swallow. Any information?

Best,
Frank