[英]Linking with cygwin
我有一個小程序,它由一個匯編函數和一個調用它的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的main': /cygdrive/c/ass0/main.c:15: undefined reference to
:錯誤:ld返回1退出狀態makefile:3:目標'ass0'的配方失敗:*** [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
生成文件代碼:
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
幫助將是最貼切的
由用戶'tvin'解決-嘗試將您的原型修改為exint int strToLeet(char *)asm(“ strToLeet”); – tivn
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.