c - 链接程序

标签 c assembly tasm

我一直在尝试用在Windows XP上运行的tasm编译asm文件。

Tasm32 版本 - Turbo Assembler 版本 5.0 版权所有 (c) 1988, 1996 Borland International

Turbo Link 版本 1.6.71.0 版权所有 (c) 1993,1996 Borland International

将当前目录设置为 tasm\bin 后,我能够执行以下操作 -

TASM32 /m29A /ml filename.asm

这会生成正常的 .Obj 文件。到目前为止,一切都很好。然后我尝试使用 -

进行链接
TLINK32 -Tpe -aa -x filename.obj,,,"kernel32.lib"

我正在使用 kernel32.lib 的适当路径

但它抛出以下错误 -

致命:无法打开文件“filename.obj,,,C:\Program Files\Microsoft SDKs\Windo” ws\v6.0A\Lib\Kernel32.lib'

我对 asm 知之甚少,并在 Google 上寻找解决方案,但似乎找不到。链接器似乎将所有内容都视为一个文件。

任何帮助将不胜感激,因为我完全不知道如何解决这个问题。

谢谢。

最佳答案

我安装了 Borland C++ Builder 5,其中包括 tasm32 和 tlink32。 TASM32打印的命令行选项如下:

Turbo Assembler  Version 5.3  Copyright (c) 1988, 2000 Inprise Corporation
Syntax:  TASM [options] source [,object] [,listing] [,xref]
/a,/s          Alphabetic or Source-code segment ordering
/c             Generate cross-reference in listing
/dSYM[=VAL]    Define symbol SYM = 0, or = value VAL
/e,/r          Emulated or Real floating-point instructions
/h,/?          Display this help screen
/iPATH         Search PATH for include files
/jCMD          Jam in an assembler directive CMD (eg. /jIDEAL)
/kh#           Hash table capacity # symbols
/l,/la         Generate listing: l=normal listing, la=expanded listing
/ml,/mx,/mu    Case sensitivity on symbols: ml=all, mx=globals, mu=none
/mv#           Set maximum valid length for symbols
/m#            Allow # multiple passes to resolve forward references
/n             Suppress symbol tables in listing
/os,/o,/op,/oi Object code: standard, standard w/overlays, Phar Lap, IBM
/p             Check for code segment overrides in protected mode
/q             Suppress OBJ records not needed for linking
/t             Suppress messages if successful assembly
/uxxxx         Set version emulation, version xxxx
/w0,/w1,/w2    Set warning level: w0=none, w1=w2=warnings on
/w-xxx,/w+xxx  Disable (-) or enable (+) warning xxx
/x             Include false conditionals in listing
/z             Display source line with error message
/zi,/zd,/zn    Debug info: zi=full, zd=line numbers only, zn=none

TLINK32打印的命令行选项如下:

Turbo Link  Version 2.5.0.0 Copyright (c) 1993,1998 Borland International
Syntax: TLINK32 objfiles, exefile, mapfile, libfiles, deffile, resfiles
@xxxx indicates use response file xxxx
  -m      Map file with publics     -x       No map
  -s      Detailed segment map      -L       Specify library search paths
  -M      Map with mangled names    -j       Specify object search paths
  -c      Case sensitive link       -v       Full symbolic debug information
  -Enn    Max number of errors      -n       No default libraries
  -P-     Disable code packing      -H:xxxx  Specify app heap reserve size
  -OS     Do smart linking
  -B:xxxx Specify image base addr   -Hc:xxxx Specify app heap commit size
  -wxxx   Warning control           -S:xxxx  Specify app stack reserve size
  -Txx    Specify output file type  -Sc:xxxx Specify app stack commit size
      -Tpx  PE image            -Af:nnnn Specify file alignment
        (x: e=EXE, d=DLL)   -Ao:nnnn Specify object alignment
  -ax     Specify application type  -o       Import by ordinals
      -ap Windowing Compatible  -Vd.d    Specify Windows version
      -aa Uses Windowing API    -r       Verbose link

所以你的链接器命令行

TLINK32 -Tpe -aa -x filename.obj,,,"kernel32.lib"

有以下选项: -Tpe 表示输出文件类型 PE exe, -aa 表示应用程序类型“使用Windowing API”, -x 表示没有 map 。 由于未指定 -n 选项,因此将包含默认运行时库。

然后有六个文件名列表。列表之间用逗号分隔。如果我没记错的话,文件名是用空格分隔的。

当前您有 objfiles = filename.obj、resfiles=kernel32.lib,其他四个文件名列表为空。我认为您实际上是指 kernel32.lib 位于 libfiles 列表中。试试这个:

TLINK32 -Tpe -aa -x filename.obj, , , kernel32.lib, , 

如果您创建一个 makefile,该项目将更容易构建和维护,因为只需要一个额外的逗号即可使链接器阶段失败。您已经经历过尝试调试神秘构建配方的挫败感。

# makefile for Borland make
# *** not tested yet!  no source code.
# Not compatible with nmake.
# May be compatible with gnu make.
#
# Borland Turbo Assembler
$(TASM32)=TASM32.exe
$(TASM32FLAGS)=/m29A /ml
#
# Borland Turbo Link
$(TLINK32)=TLINK32.exe
$(TLINK32FLAGS)=-Tpe -aa -x
#
# objfiles
$(OBJ)=filename.obj
#
# exefile
$(BIN)=filename.exe
#
# mapfile
$(MAP)=
#
# libfiles
$(LIBS)=kernel32.lib
#
# deffile
$(DEF)=
#
# resfiles
$(RES)=

all: all-before $(BIN) all-after

$(BIN): filename.asm


# Turbo Assembler  Version 5.3  Copyright (c) 1988, 2000 Inprise Corporation
# Syntax:  TASM [options] source [,object] [,listing] [,xref]
.asm.o:
    $(TASM32) $(TASM32FLAGS) $<

# Turbo Link  Version 2.5.0.0 Copyright (c) 1993,1998 Borland International
# Syntax: TLINK32 objfiles, exefile, mapfile, libfiles, deffile, resfiles
# Note the commas separate the lists of filenames, not the filenames themselves
$(BIN): $(OBJ)
    $(TLINK32) $(TLINK32FLAGS) $(OBJ), $(BIN), $(MAP), $(LIBS), $(DEF), $(RES)

抱歉,这就是我能回答的问题,这里没有太多我可以实际测试的内容。希望这足以让您的构建走上正确的轨道。祝你好运!

关于c - 链接程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20323482/

相关文章:

c - 动态指针数组重新分配失败

c - EOF 符号常量

assembly - 使用 CALL 读取 RIP 避免 shellcode 中的 0xFF 字节?

assembly - 使用 3Dh 导致中断只返回 "Acces Denied"

c - 字符串数组初始化

windows - 从程序集调用 Windows API,但没有硬编码地址

assembly - 为什么DCPU-16指令的二进制表示中有一个前导1

assembly - 如何正确读取Bios数据区地址中的值?

assembly - 在 8086 中通过 TASM 使用 Pusha 和 Popa

用 [0x...] 声明的字符数组