I have the following assembler code in the at&t style:
# asmFunc.asm
.global asmFunc
.section .text
asmFunc:
pushl %ebp
movl %esp, %ebp
addl $8,%ebp
movl %ebp, %eax
addl $4,%ebp
movl %ebp, %ebx
addl %eax,%ebx
movl %ebp, %esp
popl %ebp
ret
Then, I have a cpp file as follows:
// main.cpp
#include <iostream>
extern "C" int asmFunc(int a, int b);
int main() {
int a,b;
std::cout << "Type in 1st num: \n" << std::endl;
std::cin >> a;
std::cout << "Type in 2nd num: \n" << std::endl;
std::cin >> b;
std::cout << "Assembly function asmFunc(" << a << ", " << b << ") is" << asmFunc(a,b) << std::endl;
return 0;
}
I compile the assembly code with "as asmFunc.asm -o asmFunc.o" which gives no problems. The cpp is compiled using "g++ -c main.cpp -o main.o". When I try to link the files though using "g++ main.o asnFunc.o -o start", I get the following linker error:
(.text+0xb5): undefined reference to `asmFunc'
collect2: error: ld returned 1 exit status
Why is this? I am using CygWin 32-bit for compiling and linking the sources.