我有一个小程序,它由一个汇编函数和一个调用它的C函数组成。 现在程序在UNIX系统上编译并完美运行但是在cygwin中使用makefile时出现以下错误:
gcc -m32 -g -c -o main.o main.c
gcc -g -m32 -o ass0 main.o myasm.o
main.o:在函数main':
/cygdrive/c/ass0/main.c:15: undefined reference to
_ strToLeet'中
collect2:错误:ld返回1退出状态
makefile:3:目标'ass0'的配方失败
make:*** [ass0]错误1
main.c文件的代码:
#include <stdio.h>
# define MAX_LEN 100 // Maximal line size
extern int strToLeet (char*);
int main(void) {
char str_buf[MAX_LEN];
int str_len = 0;
printf("Enter a string: ");
fgets(str_buf, MAX_LEN, stdin); // Read user's command line string
str_len = strToLeet (str_buf); // Your assembly code function
printf("\nResult string:%s\nNumber of letters converted to Leet: %d\n",str_buf,str_len);
}
汇编代码的开始:
section .data ; data section, read-write
an: DD 0 ; this is a temporary var
section .text ; our code is always in the .text section
global strToLeet ; makes the function appear in global scope
extern printf ; tell linker that printf is defined elsewhere
strToLeet: ; functions are defined as labels
push ebp ; save Base Pointer (bp) original value
mov ebp, esp ; use base pointer to access stack contents
pushad ; push all variables onto stack
mov ecx, dword [ebp+8] ; get function argument
makefile代码:
all: ass0
ass0: main.o myasm.o
gcc -g -m32 -o ass0 main.o myasm.o
main.o: main.c
gcc -m32 -g -c -o main.o main.c
myasm.o: myasm.s
nasm -g -f elf -l ass0list -o myasm.o myasm.s
帮助最适合
答案 0 :(得分:1)
由用户'tvin'解决 - 尝试修改你的原型成为extern int strToLeet(char *)asm(“strToLeet”); - tivn