64位linux编译32位程序

64位linux编译32位程序,第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

.so是linux用的 所以 要生成so 需要用gcc 和生成可执行文件类似,只是增加一些编译选项 命令如下 gcc SOURCE_FILES -fPIC -shared -o TARGET SOURCE_FILES可以是.c文件,也可以是经过-c编译出来的.o文件 TARGET为so文件。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8406339.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-16
下一篇2023-04-16

发表评论

登录后才能评论

评论列表(0条)

    保存