Callin assembler function from C++
Callin assembler function from C++
(OP)
Hello!
My problem is that i dont know how to call an assembler function from a C++ program. I wonder i someone can see what i have done wrong in the code below?
It is intel assembler on Linux ubuntu platform and i use the g++ compiler.
I get this error message when i link the c objectfile and the assembler file:
g++ function.s function_call.o -o function_call
function_call.o: In function `main':
function_call.cpp:(.text+0x84): undefined reference to `my_function()'
This is my code
My problem is that i dont know how to call an assembler function from a C++ program. I wonder i someone can see what i have done wrong in the code below?
It is intel assembler on Linux ubuntu platform and i use the g++ compiler.
I get this error message when i link the c objectfile and the assembler file:
g++ function.s function_call.o -o function_call
function_call.o: In function `main':
function_call.cpp:(.text+0x84): undefined reference to `my_function()'
This is my code
CODE
C++ code:
#include<iostream>
extern void my_function();
int main()
{
my_function();
}
Assembler code:
.file "function.s"
.data
msg: .string "Hello\n"
len = . - msg - 1
.text
.align 2
.globl _my_function
.type _my_function, @function
_my_function:
pushl $len
pushl $msg
pushl $1
call write
addl $12, %esp
pushl $0
call exit
ret
.LFE2:
.size main, .-main
.size _my_function, .-_my_function
.globl __gxx_personality_v0
.ident "GCC: (GNU) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)"
.section .note.GNU-stack,"",@progbits
#include<iostream>
extern void my_function();
int main()
{
my_function();
}
Assembler code:
.file "function.s"
.data
msg: .string "Hello\n"
len = . - msg - 1
.text
.align 2
.globl _my_function
.type _my_function, @function
_my_function:
pushl $len
pushl $msg
pushl $1
call write
addl $12, %esp
pushl $0
call exit
ret
.LFE2:
.size main, .-main
.size _my_function, .-_my_function
.globl __gxx_personality_v0
.ident "GCC: (GNU) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)"
.section .note.GNU-stack,"",@progbits
RE: Callin assembler function from C++
extern "C" void my_function();
You can also use this command,
nm function_call.o
to find out the actual name of the symbols being generated.
--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
RE: Callin assembler function from C++
Unfortunatly i still get the same error message.
RE: Callin assembler function from C++
nm function_call.o
RE: Callin assembler function from C++
Thanks again!