I have 2 files to compile. The first is main.c and the 2nd is a function that does sums and multiplications in assembly (work.s).
This is the code :
main.c file:
#include <stdio.h>
short work();
int main() {
short z = work();
printf("work(); -> %hd\n", z);
return 0;
}
work.s file:
.globl work;
work :
xorl %eax,%eax;
xorl %ecx,%ecx;
movw $20,%ax;
subw $2,%ax;
movw $7,%cx;
addw $3,%cx;
movw $10,%cx;
subw $3,%cx;
shl $1,%cx;
addw %cx,%ax;
ret;
From command line using gcc : gcc -m32 main.c work.s -o main
This is the output :
Undefined symbols for architecture i386:
"_work", referenced from: _main in main-fbbcca.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
While on Linux with same files and commands it works, why and how I can fix it?