c - 如何在 32 位汇编中编译?

标签 c windows gcc assembly x86

嘿,我在我的 C 代码中使用了一个 32 位汇编函数。我用 nasm 和 gcc 编译它。

nasm -f coff array1.asm
gcc -o array1 array1.o array1c.c

我总是得到错误:

A
array1c.c:9:1: warning: ‘cdecl’ attribute ignored [-Wattributes]
 int PRE_CDECL asm_main( void ) POST_CDECL;
 ^~~
array1c.c:10:1: warning: ‘cdecl’ attribute ignored [-Wattributes]
 void PRE_CDECL dump_line( void ) POST_CDECL;
 ^~~~
/usr/bin/ld: i386-Architektur der Eingabedatei »array1.o« ist inkompatibel zur Ausgabe i386:x86-64
collect2: error: ld returned 1 exit status

那是我的代码:

/*
 * Driver file for array1.asm file
 */

#include <stdio.h>

#include "cdecl.h"

int PRE_CDECL asm_main( void ) POST_CDECL;
void PRE_CDECL dump_line( void ) POST_CDECL;

int main()
{
  int ret_status;
  ret_status = asm_main();
  return ret_status;
}

/*
 * function dump_line
 * dumps all chars left in current line from input buffer
 */
void dump_line()
{
  int ch;

  while( (ch = getchar()) != EOF && ch != '\n')
    /* null body*/ ;
}

最佳答案

您应该使用 gcc -m32 将代码编译为 32 位,如下所示:

nasm -f coff array1.asm
gcc -m32 -o array1 array1.o array1c.c

关于c - 如何在 32 位汇编中编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58492136/

相关文章:

c - 在使用 Autotools 构建的 C 程序中定位数据文件

c - 为什么 Windows 上的 MinGW 不需要静态链接?

c - 在 C 头文件中声明的结构 - gcc malloc 错误

c++ - winsock编译错误,找不到addrinfo结构和一些相关函数

c - 打印所有素数直到 N

c - 在 C 指针中反转字符串?

iphone - 发布 C 库(带 ARC)

c++ - Linux 和 C/C++ :Appliction created by linking libc-2. 11 并尝试在具有 libc-2.5.so 的 Linux 机器上运行

windows - 如何使用Dragon NaturallySpeaking的高级脚本使扬声器静音?

python - 单击应用程序时 Windows-Pyinstaller 错误 "failed to execute script "