nasm gcc command error with subprogram as seperate file

*爱你&永不变心* 提交于 2020-06-09 05:25:31

问题


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 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.

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!