Makefile 求助啊.....
新手第一次弄Makefile, 各种不懂,请大神帮忙看一下以下是所有程序,但是运行cipher的时候老是说no file,测试的时候是显示:
cipher.c:(.text+0x67): undefined reference to `encrypt'
cipher.c:(.text+0x77): undefined reference to `decrypt'
collect2: error: ld returned 1 exit status
快要被逼疯了......
Makefile.c
程序代码:
# Makefile CC = gcc CFLAGS = -Wall CSRC = cipher.c vigenere.c HSRC = vigenere.h OBJ = $(CSRC:.c=.o) %o:%c $(HSRC) $(CC) $(CFLAGS) -c $< # Additional targets .PHONY: clean .PHONY: test # Target rules cipher: $(OBJ) $(CC) $(CFLAGS) -o cipher $(OBJ) clean: rm -f $(OBJ) test: cipher test.dat ./cipher < test.dat
cipher.c
程序代码:
#include <stdio.h> #include "vigenere.h" char key[MAX_KEY]; int main( void ) { int ch; int option; printf("Enter key: "); scanf( "%s", key ); printf("Encrypt or Decrypt? "); while((option = getchar()) != 'e' && option != 'd') { printf("Enter text:\n"); while(( ch = getchar()) != EOF ) { if(option == 'e') { encrypt( ch ); } else { decrypt( ch ); } } } printf( "\n" ); return 0; }
vigenere.c
程序代码:
#include <stdio.h> #include <ctype.h> #include "vigenere.h" #define MAX_COL 80 void encrypt( int ch ) { /* These variables are declared "static" because they need to keep their values from one call of encrypt() to another. They will be initialized the first time encrypt() is called. After that, they will keep the value from the previous call. */ static char *p = key; static int col = 1; int i,j,k; if( isalpha(ch)) { /* convert all characters to lowercase, perform vigenere encoding and print encoded character */ i = tolower(ch) - 'a'; j = tolower(*p) - 'a'; k = ( i + j ) % 26; ch= k + 'a'; putchar( ch ); /* if we have filled a row, print newline and start a new row */ col++; if( col == MAX_COL ) { putchar( '\n' ); col = 1; } /* move to next character of key. if we have reached end of key, go back to beginning */ p++; if( *p == '\0' ) { p = key; } } } void decrypt( int ch ) { static char *p = key; static int col = 1; int i,j,k; if( isalpha(ch)) { i = tolower(ch) - 'a'; j = tolower(*p) - 'a'; k = ( i + j + 26 ) % 26; ch= k + 'a'; putchar( ch ); col++; if( col == MAX_COL ) { putchar( '\n' ); col = 1; } p++; if( *p == '\0' ) { p = key; } } }
vigenere.h
程序代码:
#define MAX_KEY 128 extern char key[MAX_KEY]; void encrypt( int ch ); void decrypt( int ch );
[ 本帖最后由 cyy06180521 于 2015-9-20 16:22 编辑 ]