nasm gcc命令错误,带有子程序的单独文件 [英] nasm gcc command error with subprogram as seperate file

查看:81
本文介绍了nasm gcc命令错误,带有子程序的单独文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将子程序作为nasm中的外部文件进行测试.运行后:

testing subprograms as external files in nasm. After running :

nasm -f elf subprogram2.asm
nasm -f elf get_int.asm

然后我运行gcc:

gcc subprogram2.o get_int.o -o stuff.exe

然后我得到以下错误:

subprogram2.o: In function 'main':
subprogram2.asm:(.text+0x19): undefined reference to 'get_int'
subprogram2.asm:(.text+0x3d): undefined reference to 'get_int'
collect2: error: ld returned 1 exit status

包含main的文件的

section .text同时具有extern get_intglobal get_int

section .text of the file containing main has both the extern get_int and global get_int

,我正在使用main中的子程序进行调用和返回. 我还将指出,我正在32位ubuntu linux上的vm上运行它.

and I am using a call and return for the subprogram in my main. I will also point out I am running this on a vm on 32-bit ubuntu linux.

推荐答案

NASM手册:

GLOBALEXTERN的另一端:如果一个模块将符号声明为EXTERN并引用该符号,则为了防止链接器错误,某些其他模块必须实际定义该符号并将其声明为GLOBAL.

GLOBAL is the other end of EXTERN: if one module declares a symbol as EXTERN and refers to it, then in order to prevent linker errors, some other module must actually define the symbol and declare it as GLOBAL.

因此,如果在get_int.asm中定义了get_int,则应将global get_int放入get_int.asm中,并在要使用get_int的任何其他文件中将其声明为extern.

So if get_int is defined in get_int.asm you should put the global get_int in get_int.asm, and declare it as extern in any other files that want to use get_int.

这篇关于nasm gcc命令错误,带有子程序的单独文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆