C warning: implicit declaration of function -
yes, question has been asked many times, , i've been looking , reading forums, , posts, answers unrelated (or seem) one. so, have main file :
-- sgbd_server.c --
#include "sgbd_server.h" /** * open server pipe , return handle. -1 = error */ int open_server_pipe() { return pipe_open(fifo_name, o_rdonly, s_con_color); } /** * close server pipe */ void close_server_pipe(int fd) { pipe_close(fd, fifo_name, s_con_color); } int main(int argc, char *argv[]) { int pipe_fd; pipe_fd = open_server_pipe(); if (pipe_fd == -1) { perror("cannot open pipe"); } close_server_pipe(pipe_fd); exit(exit_success); }
then header files :
-- sgbd_server.h --
#include "common.h" #define fifo_name "./sgbd_server_pipe" #define buffer_size pipe_buf #define s_con_color 1 /* c_color_red */
-- common.h --
#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <fcntl.h> #include <limits.h> #include <sys/types.h> #include <sys/stat.h> #include "console.h" #define client_fifo_prefix = "./sgbd_client_" int pipe_open(char *f, int mode, int color); void pipe_close(int pipe_fd, char *f, int color);
the 2 functions pipe_open
, pipe_close
defined in pipe.c
, returning 0
, void
. last file compiled separately in make file.
i'm not guru @ making make files, sake of question, here :
server = sgbd_server client = sgbd_client cc = gcc c_flags = -wall -i. linker = gcc l_flags = -wall -l pthread -wall -i. rm = rm -f client: sgbd_client.o pipe.o console.o @echo -n "building client... " @$(linker) $(l_flags) -o $(client) sgbd_client.o pipe.o console.o @echo "complete!\n" server: sgbd_server.o pipe.o console.o @echo -n "building server... " @$(linker) $(l_flags) -o $(server) sgbd_server.o pipe.o console.o @echo "complete!\n" sgbd_client.o: sgbd_client.c @echo -n "refreshing client sources... " @$(cc) $(c_flags) -c sgbd_client.c @echo "done!" sgbd_server.o: sgbd_server.c common.h @echo -n "refreshing server sources..." @$(cc) $(c_flags) -c sgbd_server.c common.h @echo "done!" pipe.o: pipe.c @echo -n "refreshing pipe sources..." @$(cc) $(c_flags) -c pipe.c @echo "done!" console.o: console.c @echo -n "refreshing console sources..." @$(cc) $(c_flags) -c console.c @echo "done!" clean: @echo -n "cleaning executables , object files... " @$(rm) $(server) $(client) *.o @echo "ok\n"
** note ** : file console.c
, implements functions control i/o on console, nothing fancy. see, compiled separately.
now, when type make client
, , birds signing, etc. etc. when type make server
, spits out
sgbd_server.c: in function ‘open_server_pipe’: sgbd_server.c:7: warning: implicit declaration of function ‘pipe_open’ sgbd_server.c: in function ‘close_server_pipe’: sgbd_server.c:14: warning: implicit declaration of function ‘pipe_close’
i'm running gcc on linux amd64 if makes difference (i doubt it).
now, why warn me that? 2 functions declared in common.h
, included in sgbd_server.h
... missing here?
thank time!
** update **
thank suggestion. did try find if there file common.h
somewhere else in include path included somehow... while failed find have slipped in compilation process instead of local common.h
(sig) found .ghc
files sitting in source folder. since not cleaned make clean
, deleted manually files. guess what? no warning. files , why created?
for start, don't think it's idea giving common.h
compiler in makefile:
@$(cc) $(c_flags) -c sgbd_server.c common.h
this better just:
@$(cc) $(c_flags) -c sgbd_server.c
header files incorporated #include
. appear telling compiler try , compile common.h
standalone c file. that's 1 difference between client , server compile commands , should fix it.
the other thing can suggest may not getting header files think you're getting. start putting line:
#error urk! in common.h
at top of common.h
, ensure build fails there.
if not, file coming somewhere else. may want same thing sgbd_server.h
file well.
based on edit:
i found .ghc files sitting in source folder. since not cleaned make clean, deleted manually files. guess what? no warning. files , why created?
these are, assuming ghc
typo , meant gch
, pre-compiled headers generated gcc
, @ least in part speed compilation process. rather having process header file many times during build (once per source file includes it), pre-compiling once , using pre-compiled version lot more efficient.
i think cause fact included common.h
on compiler command line when did server. default, header files given directly gcc
turned pre-compiled header files , used in preference after point. test this, created qq.h
file , executed gcc qq.h
, out popped qq.h.gch
.
it's quite likely, given deleting them solved problem, these files somehow causing issues (be presence of pre-compiled headers older real headers or else entirely). there's chance compile line:
@$(cc) $(c_flags) -c sgbd_server.c common.h
would first compile server program, including old precompiled header, then make new precompiled header out of newer header file.
that's why change common.h
had no (immediate) effect. have make ; touch common.h ; make
ensure newer pre-compiled header file used in server program.
whether want track root cause , proper explanation matter of taste - there's school of thought should record how fixed , not worry much, lest become entangled in nature of reality itself.
not me of course, i'm personality type attempt track problems individual sub-atomic particle caused it, pragmatism requires me let go :-)
Comments
Post a Comment