免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2637 | 回复: 2
打印 上一主题 下一主题

请教一段程序编译的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-05-22 03:35 |只看该作者 |倒序浏览
  1. Makefile的编写
  2. 假设我们有下面这样的一个程序,源代码如下:

  3. /* main.c */
  4. #include "mytool1.h"
  5. #include "mytool2.h"

  6. int main(int argc,char **argv)
  7. {
  8. mytool1_print("hello");
  9. mytool2_print("hello");
  10. }

  11. /* mytool1.h */
  12. #ifndef _MYTOOL_1_H
  13. #define _MYTOOL_1_H

  14. void mytool1_print(char *print_str);

  15. #endif

  16. /* mytool1.c */
  17. #include "mytool1.h"
  18. void mytool1_print(char *print_str)
  19. {
  20. printf("This is mytool1 print %s\n",print_str);
  21. }

  22. /* mytool2.h */
  23. #ifndef _MYTOOL_2_H
  24. #define _MYTOOL_2_H

  25. void mytool2_print(char *print_str);

  26. #endif

  27. /* mytool2.c */
  28. #include "mytool2.h"
  29. void mytool2_print(char *print_str)
  30. {
  31. printf("This is mytool2 print %s\n",print_str);
  32. }


  33. 当然由于这个程序是很短的我们可以这样来编译
  34. gcc -c main.c
  35. gcc -c mytool1.c
  36. gcc -c mytool2.c
  37. gcc -o main main.o mytool1.o mytool2.o
复制代码


我在编译main.c的时候,得到如下错误提示
In file included from main.c:2:
mytool1.h:2:2: invalid preprocessing directive #ifndef_MYTOOL_1_H
mytool1.h:3:2: invalid preprocessing directive #define_MYTOOL_1_H
mytool1.h:7:2: #endif without #if
In file included from main.c:3:
mytool2.h:2:2: invalid preprocessing directive #ifndef_MYTOOL_2_H
mytool2.h:3:2: invalid preprocessing directive #define_MYTOOL_2_H
mytool2.h:7:2: #endif without #if

这是在一个教程上看到的例子,不能全部明白其意思,故求解

下面是系统环境
Linux 2.6.9-5.EL i686 i686 i386 GNU/Linux
Red Hat 3.4.3-9.EL4
gcc version 3.4.3
CPU:Intel(R) Celeron(TM) CPU 1000MHz
MemTotal: 256064 kB

论坛徽章:
0
2 [报告]
发表于 2006-05-22 11:31 |只看该作者
老大,#ifndef和#define后要用空格的。
#ifndef_MYTOOL_1_H要写成#ifndef _MYTOOL_1_H才行。

论坛徽章:
0
3 [报告]
发表于 2006-05-22 15:23 |只看该作者
啊,啊,啊,谢谢elila的指点
刚开始学c语言,对c语言里的很多语法都不熟悉,谢谢指点
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP