问题
testing subprograms as external files in nasm. After running :
nasm -f elf subprogram2.asm
nasm -f elf get_int.asm
I then run the gcc:
gcc subprogram2.o get_int.o -o stuff.exe
I then get the following error:
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
section .text
of the file containing main
has both the extern get_int
and global get_int
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.
回答1:
Quoting from the NASM manual:
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
.
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
.
来源:https://stackoverflow.com/questions/29462853/nasm-gcc-command-error-with-subprogram-as-seperate-file