首页 文章

与cygwin联系

提问于
浏览
0

我有一个小程序,它由汇编函数和调用它的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: error: ld returned 1 exit status makefile:3: recipe for target ' 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

帮助将是最受关注的

1 回答

  • 1

    用户'tvin'解决 - 尝试修改你的原型成为extern int strToLeet(char *)asm(“strToLeet”); - tivn

相关问题