如何在64位版本Linux上开发运行32位应用程序

2025-05-08 11:13:42
推荐回答(1个)
回答(1):

在64位的Linux下,gcc 编译 32 位程序需要添加参数 -m32 ,ld需要添加参数是 -m elf_i386。
1、Along with the -m32 flag in gcc, you may need to include the -melf_i386 flag for ld to properly link the 32bit object files to the 32bit libraries if you have both the 32bit and 64bit libraries.
2、 ld命令 ld命令是GNU的连接器,将目标文件连接为可执行程序。
3、举例:

gcc -m32 -o hello hello.c

gcc -m32 -c hello.o hello.c
ld -m elf_i386 -o kernel main.o hello.o