0
我有一個由程序集函數和C函數調用的小程序。 現在程序編譯和完美的作品在UNIX系統上,但在Cygwin中使用Makefile時,我得到以下錯誤:與cygwin鏈接
的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
的幫助將是非常appriciated
'strToLeet'似乎是一個函數。在C中,所需要的只是一個原型,而不是'extern'語句。 – user3629249
asm文件是否包含必要的語句以使strToLeet()函數在應用程序的其餘部分中可見? – user3629249
strToLeet是一個用匯編寫的函數, – yair