【问题标题】:GCC and NASM link to external libraryGCC 和 NASM 链接到外部库
【发布时间】:2012-06-05 19:25:06
【问题描述】:

我想在 Assembly(使用 NASM)中创建一个简单的应用程序,它将获取命令行参数。现在我使用extern _GetCommandLineAcall _GetCommandLineA 来调用该函数。我编译代码并从 NASM 获取目标文件。 现在我想使用 GCC 来链接和创建 EXE。我不想使用标准库,所以我使用这个命令来构建可执行文件:

gcc test.obj -s -nostartfiles -nostdlib -nodefaultlibs -o test.exe

它给我一个Undefined reference to GetCommandLineA 错误,作为 ASM 的初学者,我不知道为什么?一些帮助将不胜感激。提前致谢!

【问题讨论】:

    标签: gcc command-line nasm undefined-reference


    【解决方案1】:

    GetCommandLineAGetCommandLineWkernel32.dll 中定义,与大多数 Windows API 一样,它使用 WINAPI (stdcall) calling convention

    为了从程序集中调用此函数,您需要指定完全“装饰”的符号名称,在本例中为 _GetCommandLineA@0

    将程序集文件中的_GetCommandLineA 替换为_GetCommandLineA@0

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-17
      相关资源
      最近更新 更多