64位汇编下的link问题

C4SDN_no 2011-09-16 12:11:36
请大虾们帮忙了,,,
EXTRN MessageBoxA:PROC
EXTRN ExitProcess:PROC

INCLUDELIB kernel32.lib
INCLUDELIB user32.lib

MB_OKCANCEL EQU 1
;***************************************************
.DATA
szTitle BYTE '最简单的程式',0
szText BYTE '这是在 Windows 64 位操作系统,',0dh,0ah
BYTE '用汇编语言写的程序。',0
;***************************************************
.CODE
;---------------------------------------------------
Main PROC
sub rsp,28h
mov r9,MB_OKCANCEL
mov r8,OFFSET szTitle
mov rdx,OFFSET szText
sub rcx,rcx
call MessageBoxA
add rsp,28h
ret
Main ENDP
END




就是上面这个,我在网上找的,可是,我用vs2010的x64工具,总是提醒link必须定义入口,,郁闷了

Setting environment for using Microsoft Visual Studio 2010 x64 tools.

d:\新建文件夹 (6)\VC>ml64 H:assembly\hellowworld.asm/link
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: H:assembly\hellowworld.asm/link
MASM : fatal error A1000:cannot open file : H:assembly\hellowworld.asm/link

d:\新建文件夹 (6)\VC>ml64 H:assembly\hellowworld.asm
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: H:assembly\hellowworld.asm
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

/OUT:hellowworld.exe
hellowworld.obj
LINK : fatal error LNK1561: 必须定义入口点

...全文
796 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
半字节 2011-09-17
  • 打赏
  • 举报
回复
补充 ,如果你的链接器要求入口函数必须是main, 那么你需要把上面的改成main
半字节 2011-09-17
  • 打赏
  • 举报
回复
你这样试试,我觉得可能有以下原因,第一没找到入口,第二是使用了重复定义,至于大小写,好像是不关键的,windows环境好像不区分大小写,不过为了严格一致 ,建议写成一样的

EXTRN MessageBoxA:PROC
EXTRN ExitProcess:PROC

INCLUDELIB kernel32.lib
INCLUDELIB user32.lib

MB_OKCANCEL EQU 1
;***************************************************
.DATA
szTitle BYTE '最简单的程式',0
szText BYTE '这是在 Windows 64 位操作系统,',0dh,0ah
BYTE '用汇编语言写的程序。',0
;***************************************************
.CODE
;---------------------------------------------------
Mainmainmain PROC
MainmainStart:
sub rsp,28h
mov r9,MB_OKCANCEL
mov r8,OFFSET szTitle
mov rdx,OFFSET szText
sub rcx,rcx
call MessageBoxA
add rsp,28h
ret
Mainmainmain ENDP
END Mainmainstart

C4SDN_no 2011-09-17
  • 打赏
  • 举报
回复
非常感谢大家,,,这个问题终于搞定了,,下面是我和你们的成果,(开始实验,所以可能有点逊~~呵呵看最后一个~~~~!!@)
Setting environment for using Microsoft Visual Studio 2010 x64 tools.

d:\新建文件夹 (6)\VC>ml64 H:assembly\hellow.asm
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: H:assembly\hellow.asm
H:assembly\hellow.asm(17) : error A2008:syntax error : mainmainstart
H:assembly\hellow.asm(27) : error A2008:syntax error : mainmainstart
H:assembly\hellow.asm(27) : error A2088:END directive required at end of file

d:\新建文件夹 (6)\VC>ml64 H:assembly\hellow.asm
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: H:assembly\hellow.asm
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

/OUT:hellow.exe
hellow.obj
LINK : fatal error LNK1561: 必须定义入口点

d:\新建文件夹 (6)\VC>
d:\新建文件夹 (6)\VC>ml64 /c H:assembly\hellow.asm
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: H:assembly\hellow.asm

d:\新建文件夹 (6)\VC>link /system:windows/entry:main hellow.obj
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

LINK : warning LNK4044: 无法识别的选项“/system:windows/entry:main”;已忽略
LINK : fatal error LNK1561: 必须定义入口点

d:\新建文件夹 (6)\VC>link /system:windows/entry:main|hellow.obj

d:\新建文件夹 (6)\VC>link /system:windows/entry:main/hellow.obj
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

LINK : warning LNK4044: 无法识别的选项“/system:windows/entry:main/hellow.obj”
;已忽略
LINK : warning LNK4001: 未指定对象文件;已使用库
LINK : warning LNK4068: 未指定 /MACHINE;默认设置为 X64
LINK : fatal error LNK1561: 必须定义入口点

d:\新建文件夹 (6)\VC>ml64 /c H:assembly\hellow.asm
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: H:assembly\hellow.asm

d:\新建文件夹 (6)\VC>link /system:windows
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

LINK : warning LNK4044: 无法识别的选项“/system:windows”;已忽略
LINK : warning LNK4001: 未指定对象文件;已使用库
LINK : warning LNK4068: 未指定 /MACHINE;默认设置为 X64
LINK : fatal error LNK1561: 必须定义入口点

d:\新建文件夹 (6)\VC>link /system:windows/entry:main hellow.obj
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

LINK : warning LNK4044: 无法识别的选项“/system:windows/entry:main”;已忽略
LINK : fatal error LNK1561: 必须定义入口点

d:\新建文件夹 (6)\VC>cl H:assembly
用于 x64 的 Microsoft (R) C/C++ 优化编译器 16.00.40219.01 版
版权所有(C) Microsoft Corporation。保留所有权利。

cl: 命令行 warning D9024 :无法识别的源文件类型“H:assembly”,假定为对象文件
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

/out:assembly.exe
H:assembly
LINK : fatal error LNK1181: 无法打开输入文件“H:assembly.obj”

d:\新建文件夹 (6)\VC>cl H:assembly\hellow.asm
用于 x64 的 Microsoft (R) C/C++ 优化编译器 16.00.40219.01 版
版权所有(C) Microsoft Corporation。保留所有权利。

cl: 命令行 warning D9024 :无法识别的源文件类型“H:assembly\hellow.asm”,假定为
对象文件
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

/out:hellow.exe
H:assembly\hellow.asm
H:assembly\hellow.asm : fatal error LNK1107: 文件无效或损坏: 无法在 0x325 处读取


d:\新建文件夹 (6)\VC>cl
用于 x64 的 Microsoft (R) C/C++ 优化编译器 16.00.40219.01 版
版权所有(C) Microsoft Corporation。保留所有权利。

用法: cl [ 选项... ] 文件名... [ /link 链接选项... ]

d:\新建文件夹 (6)\VC>ml64 H:assembly\hellow.asm/link entry:main
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: H:assembly\hellow.asm/link
MASM : fatal error A1000:cannot open file : H:assembly\hellow.asm/link

d:\新建文件夹 (6)\VC>ml
'ml' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

d:\新建文件夹 (6)\VC>ml64
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

usage: ML64 [ options ] filelist [ /link linkoptions]
Run "ML64 /help" or "ML64 /?" for more info

d:\新建文件夹 (6)\VC>ml64 H:assembly\hellow.asm /link entry:main
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: H:assembly\hellow.asm
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

/OUT:hellow.exe
hellow.obj
entry:main
LINK : fatal error LNK1181: 无法打开输入文件“entry:main.obj”

d:\新建文件夹 (6)\VC>ml64 H:assembly\hellow.asm /link /entry:main
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: H:assembly\hellow.asm
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

/OUT:hellow.exe
hellow.obj
/entry:main
LINK : error LNK2001: 无法解析的外部符号 main
hellow.exe : fatal error LNK1120: 1 个无法解析的外部命令

d:\新建文件夹 (6)\VC>ml64 H:assembly\hellow.asm /link /entry:Main
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: H:assembly\hellow.asm
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

/OUT:hellow.exe
hellow.obj
/entry:Main
LINK : fatal error LNK1221: 无法推导出子系统,必须定义它

d:\新建文件夹 (6)\VC>set ml=/link /subsystem:windows

d:\新建文件夹 (6)\VC>ml64 H:assembly\hellow.asm /link /entry:Main
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: H:assembly\hellow.asm
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

/OUT:hellow.exe
hellow.obj
/subsystem:windows
/entry:Main //要的就是这个结果,
我们成功了~!~!~
G_Spider 2011-09-17
  • 打赏
  • 举报
回复
ml64 /c hellowworld.asm
link /subsystem:windows /entry:Main hellowworld.obj

指定入口点。
zara 2011-09-16
  • 打赏
  • 举报
回复
啊,应该是 END Main 吧,大小写的问题?
C4SDN_no 2011-09-16
  • 打赏
  • 举报
回复
你好zara:
我试过了,还是
d:\新建文件夹 (6)\VC>ML64 H:assembly\hellowworld.asm
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: H:assembly\hellowworld.asm
H:assembly\hellowworld.asm(26) : error A2008:syntax error : MAIN
H:assembly\hellowworld.asm(26) : error A2088:END directive required at end of fi
le

~!不过,还是要谢谢你的回答!!@
G_Spider 2011-09-16
  • 打赏
  • 举报
回复
You can use fasm or JWasm.
zara 2011-09-16
  • 打赏
  • 举报
回复
将最后一行的 END 改为 END MAIN ,即指定程序从 MAIN 子程开始运行试试?汇编和 c 不同,不以标号名称来自动定位程序开始运行的入口点;必须通过 END 语句来指定。
C4SDN_no 2011-09-16
  • 打赏
  • 举报
回复
Setting environment for using Microsoft Visual Studio 2010 x64 tools.

d:\新建文件夹 (6)\VC>ML64 H:assembly\hellowworld.asm
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: H:assembly\hellowworld.asm
H:assembly\hellowworld.asm(16) : error A2008:syntax error : MAIN
H:assembly\hellowworld.asm(25) : error A2008:syntax error : MAIN
H:assembly\hellowworld.asm(25) : error A2088:END directive required at end of fi
le

这个改法也不行,,,谢谢上面了,,,,,,
C4SDN_no 2011-09-16
  • 打赏
  • 举报
回复
应该支持的是64位汇编,它就是x64汇编器呀,,,
Tishion 2011-09-16
  • 打赏
  • 举报
回复
你先去看一下VS2010支持的是X86汇编还是Win32汇编。
Michael_g 2011-09-16
  • 打赏
  • 举报
回复
EXTRN MessageBoxA:PROC
EXTRN ExitProcess:PROC

INCLUDELIB kernel32.lib
INCLUDELIB user32.lib

MB_OKCANCEL EQU 1
;***************************************************
.DATA
szTitle BYTE '最简单的程式',0
szText BYTE '这是在 Windows 64 位操作系统,',0dh,0ah
BYTE '用汇编语言写的程序。',0
;***************************************************
.CODE
;---------------------------------------------------
Main:
sub rsp,28h
mov r9,MB_OKCANCEL
mov r8,OFFSET szTitle
mov rdx,OFFSET szText
sub rcx,rcx
call MessageBoxA
add rsp,28h
ret
END Main
C4SDN_no 2011-09-16
  • 打赏
  • 举报
回复
你好 otishion
我按照你的方法改了,可是也不行啊
Setting environment for using Microsoft Visual Studio 2010 x64 tools.



d:\新建文件夹 (6)\VC>ml64 H:assembly\hellowworld.asm
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: H:assembly\hellowworld.asm
H:assembly\hellowworld.asm(16) : error A2008:syntax error : .
H:assembly\hellowworld.asm(25) : error A2008:syntax error : .

不过,也感谢你的回复,,我会继续找答案的,完了大家一起分享!~!~!~!

Tishion 2011-09-16
  • 打赏
  • 举报
回复
.CODE
;---------------------------------------------------
.starup
sub rsp,28h
mov r9,MB_OKCANCEL
mov r8,OFFSET szTitle
mov rdx,OFFSET szText
sub rcx,rcx
call MessageBoxA
add rsp,28h
ret
.exit
END

21,458

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧