gcc -o hellomake hellomake.c hellofunc.c -I.
How do I remove the following warnings (on ubuntu 12.04), without putting all the code in one file?
hellofunc.c: In function 'myPrintHelloMake': hellofunc.c:6:3: warning: incompatible implicit declaration of built-in function 'printf' [enabled by default]
The three files are as follows:
hellomake.c
#include<stdio.h>
int main()
{ // call a function in another file myPrintHelloMake();
return(0);
}
hellofunc.c
#include<hellomake.h>
void myPrintHelloMake(void) {
printf("Hello makefiles!\n");
return;
}
hellomake.h /* example include file */
void myPrintHelloMake(void);
Since hellofunc.c
calls printf
you need to #include <stdio.h>
there.
If hellomake.c
calls your myPrintHelloMake
function, it should #include "hellomake.h"
hellomake.h
should also have include guards , eg
#ifndef HELLOMAKE_H_
#define HELLOMAKE_H_
void myPrintHelloMake(void);
#endif
#inclde<stdio.h>
应该在公共头文件中,或者hellofunc.c
包含在hellofunc.c
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.