| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 472 人关注过本帖
标题:Makefile 求助啊.....
取消只看楼主 加入收藏
cyy06180521
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2015-8-21
结帖率:100%
收藏
 问题点数:0 回复次数:1 
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 编辑 ]
搜索更多相关主题的帖子: undefined reference status 
2015-09-20 13:38
cyy06180521
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2015-8-21
收藏
得分:0 
恩,没事了,我脑子抽了,在Makefile后面也打了.c..............
2015-09-20 16:22
快速回复:Makefile 求助啊.....
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028199 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved