- 论坛徽章:
- 0
|
本帖最后由 xiangbei1573 于 2012-06-28 15:03 编辑
这是四个文件的代码:
main.c:- #include <stdio.h>
- #define pi 3.14159
- char name[15];
- float angle;
- int main(void)
- {
- printf ("\n\nPlease input your name: ");
- scanf ("%s", &name );
- printf ("\nPlease enter the degree angle (ex> 90): " );
- scanf ("%f", &angle );
- haha( name );
- sin_value( angle );
- cos_value( angle );
- }
复制代码 ----------------------------------------------------------分割线
haha.c:- #include <stdio.h>
- int haha(char name[15])
- {
- printf ("\n\nHi, Dear %s, nice to meet you.", name);
- }
复制代码 ----------------------------------------------------------分割线
sin_value.c:- #include <stdio.h>
- #define pi 3.14159
- float angle;
- void sin_value(void)
- {
- float value;
- value = sin ( angle / 180. * pi );
- printf ("\nThe Sin is: %5.2f\n",value);
- }
复制代码 ----------------------------------------------------------分割线
cos_value.c:- #include <stdio.h>
- #define pi 3.14159
- float angle;
- void cos_value(void)
- {
- float value;
- value = cos ( angle / 180. * pi );
- printf ("The Cos is: %5.2f\n",value);
- }
复制代码 ----------------------------------------------------------分割线- [root@www ~]# gcc -c main.c
- [root@www ~]# gcc -c haha.c
- [root@www ~]# gcc -c sin_value.c
- [root@www ~]# gcc -c cos_value.c
复制代码 我可以对main.c 和haha.c编译,但是对sin_value.c和cos_value.c编译的时候出错:
sin_value.c:8: warning: incompatible implicit declaration of built-in function 鈙in
cos_value.c:8: warning: incompatible implicit declaration of built-in function 鈉os?
红色的是乱码。。。。错误信息的大概含义是头文件的事情吧。。
我使用vim建立一个makefile更加不通过了:- main:main.o haha.o sin_value.o cos_value.o
- gcc -o main main.o haha.o sin_value.o cos_value.o
复制代码 ----------------------------------------------------------分割线- [root@localhost sin]# make
- cc -c -o main.o main.c
- cc -c -o haha.o haha.c
- gcc -o main main.o haha.o sin_value.o cos_value.o
- sin_value.o: In function `sin_value':
- sin_value.c:(.text+0x20): undefined reference to `sin'
- cos_value.o: In function `cos_value':
- cos_value.c:(.text+0x20): undefined reference to `cos'
- collect2: ld returned 1 exit status
- make: *** [main] Error 1
复制代码 请大家解惑,thanks a lot! |
|