nasm gcc命令错误,带有子程序的单独文件 [英] nasm gcc command error with subprogram as seperate file
问题描述
将子程序作为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_int
和global 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.
推荐答案
GLOBAL
是EXTERN
的另一端:如果一个模块将符号声明为EXTERN
并引用该符号,则为了防止链接器错误,某些其他模块必须实际定义该符号并将其声明为GLOBAL
.
GLOBAL
is the other end ofEXTERN
: if one module declares a symbol asEXTERN
and refers to it, then in order to prevent linker errors, some other module must actually define the symbol and declare it asGLOBAL
.
因此,如果在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屋!