LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 512|回复: 4

书上的例,但我不知错在哪里

[复制链接]
发表于 2004-5-19 19:49:24 | 显示全部楼层 |阅读模式
书上的一个讲解多模块的makefile的例,我make时错了。

  1. compute.h
  2. double compute(double,double);

  3. input.h
  4. double input(char *);

  5. main.h
  6. const char *PROMPT1="Enter the value of x:"
  7. const char *PROMPT2="Enter the value of y:"

  8. compute.c
  9. #include "compute.h"

  10. double compute(doulbe x, double y)
  11. {
  12.         return(prow((double)x, (double)y);
  13. }

  14. input.c
  15. #include "input.h"

  16. double input(const char *s)
  17. {
  18.         float x;

  19.         printf("%s",s);
  20.         scanf("%f",&x);
  21.         return(x);
  22. }


  23. main.c
  24. #include <stdio.h>
  25. #include "main.h"
  26. #include "compute.h"
  27. #include "input.h"

  28. main()
  29. {
  30.         double x,y;

  31.         printf("The program takes x and y rtom stdio and display X^y.\n");
  32.         x=input(PROMPT1);
  33.         y=input(PROMPT2);
  34.         printf("x^y is: %6.3f\n",compute(x,y));
  35. }


  36. makefile
  37. power:main.o input.o compute.o
  38.         gcc main.o input.o compute.o -o power -lm
  39. main.o:main.c main.h input.h compute.h
  40.         gcc -c main.c
  41. input.o:input.c input.h
  42.         gcc -c input.c
  43. compute.o:compute.c compute.h
  44.         gcc -c compute.c

复制代码

编译错
[chh@wake c]$ make
gcc -c main.c
In file included from main.c:2:
main.h:2: parse error before "const"
main.c: In function `main':
main.c:11: warning: passing arg 1 of `input' discards qualifiers from pointer target type
main.c:12: `PROMPT2' undeclared (first use in this function)
main.c:12: (Each undeclared identifier is reported only once
main.c:12: for each function it appears in.)
make: *** [main.o] 错误 1
发表于 2004-5-19 20:06:23 | 显示全部楼层
这不makefile的错,是程序出错了。
main.h的两个语句后面少了分号。加上即可。
 楼主| 发表于 2004-5-20 11:26:18 | 显示全部楼层
版主大人,我的还是不行,厚着脸皮还要请你教我。
按你说的我改了。又有新的错

  1. [chh@wake c]$ make
  2. gcc -c main.c
  3. main.c: In function `main':
  4. main.c:11: warning: passing arg 1 of `input' discards qualifiers from pointer ta
  5. rget type
  6. main.c:12: warning: passing arg 1 of `input' discards qualifiers from pointer ta
  7. rget type
  8. gcc -c input.c
  9. input.c:4: conflicting types for `input'
  10. input.h:1: previous declaration of `input'
  11. make: *** [input.o] 错误 1

复制代码

于是,我把input.h改成这个样子
double input(const char *);
于是,又有了新错。
[chh@wake c]$ make
gcc -c input.c
gcc -c compute.c
compute.c:3: parse error before "x"
compute.c: In function `compute':
compute.c:4: number of arguments doesn't match prototype
compute.h:1: prototype declaration
compute.c:5: `x' undeclared (first use in this function)
compute.c:5: (Each undeclared identifier is reported only once
compute.c:5: for each function it appears in.)
compute.c:5: `y' undeclared (first use in this function)
compute.c:5: parse error before ';' token
make: *** [compute.o] 错误 1
于是,我又改在compute.c中加了
double x,y;
于是又有
[chh@wake c]$ make
gcc -c compute.c
compute.c:5: parse error before "x"
compute.c: In function `compute':
compute.c:6: number of arguments doesn't match prototype
compute.h:1: prototype declaration
compute.c:7: parse error before ';' token
make: *** [compute.o] 错误 1
这次不知所云了。 我真的想学c语言,请版主帮助.谢谢
发表于 2004-5-20 14:47:35 | 显示全部楼层
你的compute.c中第三行参数表中的第一个double写错了,成了doulbe
 楼主| 发表于 2004-5-20 17:06:45 | 显示全部楼层
真不好意思,我太粗心了,给大家添麻烦了,谢谢两位大哥。
我已经成了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表