Can't link assembly and c -
i have problems linking c , assembly code. tried search solutions, none of found worked me.
c file "l3.c" looks this:
#include <stdio.h> #include <stdlib.h> const int inp_size = 100; extern int mult(int c1, int c2); int main() { char number[inp_size]; scanf("%s",number); printf("you typed: %s \n",number); int j=2; int k=5; j = mult(j,k); #here problem printf("%d",j); scanf("%s",number); return 0; }
and asembly "mult.s" this:
.type mult, @function mult: push %rbp mov %rsp, %rbp mov 8(%rbp), %rbx mov 12(%rbp), %rcx mov $0, %rax add %rbx, %rax; add %rcx, %rax; mov %rbp, %rsp pop %rbp ret
in makefile got following lines(most recent solution googled):
l3: -g -o mult.o mult.s gcc -o l3.o -c l3.c gcc l3.o mult.o
when type make in console throwing: undefined reference 'mult'
when comment //j = mult(j,k);
program works fine. how should link this?
it looks you're not exporting mult
symbol, linker can't find later on. how correctly depends on assembler you're using. since you're using at&t syntax, i'm going guess gnu - in case add .global mult
@ top of assembly file.
Comments
Post a Comment