64位的Ubuntu系统上使用汇编nasm和C语言
2015-08-06 10:10
357 查看
64位的Ubuntu系统上使用汇编nasm和C语言
$ nasm -f elf foo.asm -o foo.o
$ gcc -c bar.c -o bar.o
$ ld -s foo.o bar.o -o foobar
ld: i386 architecture of input file `foo.o' is incompatible with i386:x86-64 output
意思是nasm 编译产生的是32位的目标代码,gcc 在64位平台上默认产生的是64位的目标代码,
这两者在链接的时候出错,gcc在64位平台上默认以64位的方式链接。
-------------------------------------------------------------------------------------------------------
方法:
让gcc 产生32位的代码,并在链接的时候以32位的方式进行链接
在这种情况下只需要修改编译和链接指令即可,具体如下:
32位的编译链接指令
$ nasm -f elf foo.asm -o foo.o
$ gcc -m32 -c bar.c -o bar.o
$ ld -m elf_i386 -s foo.o bar.o -o foobar
$ ./foobar
the 2nd one
参考地址:http://www.linuxidc.com/Linux/2012-12/75804.htm
$ nasm -f elf foo.asm -o foo.o
$ gcc -c bar.c -o bar.o
$ ld -s foo.o bar.o -o foobar
ld: i386 architecture of input file `foo.o' is incompatible with i386:x86-64 output
意思是nasm 编译产生的是32位的目标代码,gcc 在64位平台上默认产生的是64位的目标代码,
这两者在链接的时候出错,gcc在64位平台上默认以64位的方式链接。
-------------------------------------------------------------------------------------------------------
方法:
让gcc 产生32位的代码,并在链接的时候以32位的方式进行链接
在这种情况下只需要修改编译和链接指令即可,具体如下:
32位的编译链接指令
$ nasm -f elf foo.asm -o foo.o
$ gcc -m32 -c bar.c -o bar.o
$ ld -m elf_i386 -s foo.o bar.o -o foobar
$ ./foobar
the 2nd one
参考地址:http://www.linuxidc.com/Linux/2012-12/75804.htm
相关文章推荐
- C++中重载、覆盖、隐藏之间的关系
- C++11 标准新特性: 右值引用与转移语义
- 指针与引用的区别
- (C/C++学习笔记)指针做函数参数形成回调
- C++ vector容器类型及初始化方法
- c++中的map用法详解
- C语言字符串处理函数
- Berland National Library
- python pip install tables couldn't find microsoft vc++ 9.0 (vcvarsall.bat)
- C++字符串排序
- C++中的多态
- C语言 让crash来的更猛烈些吧
- C++ 强制类型转换
- iOS-C语言和OC部分
- ncb文件
- c++调用python实现
- oc语言第九课 KVC、KVO与谓词——ios学习连载14
- 《C++ Primer Plus》03vector,array,数组的区别
- C语言的表达式与语句
- C++ 中输入输出细节