cppprogrammer
Programmer
- Dec 18, 2007
- 9
- 0
- 0
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