【发布时间】:2010-11-16 01:50:09
【问题描述】:
是的,这个问题已经被问过很多次了,我一直在寻找和阅读论坛和 SO 帖子,但答案都与这个问题无关(或者看起来如此)。所以,我有这个 main 文件:
-- sgbd_server.c --
#include "sgbd_server.h"
/**
* Open server pipe and 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);
}
然后是头文件:
-- 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);
pipe_open 和 pipe_close 两个函数在pipe.c 中定义,基本上返回0 和void。最后一个文件在 Make 文件中单独编译。
我不是制作 Make 文件的专家,但为了这个问题,这里是:
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 up executables and object files... "
@$(RM) $(SERVER) $(CLIENT) *.o
@echo "Ok\n"
** 注意 ** : 文件console.c 并实现了一些功能来控制控制台上的I/O,没什么花哨的。如您所见,它也是单独编译的。
现在,当我输入make client 时,一切都很好,鸟儿正在签名等等。但是当我输入make server 时,它会吐出来
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’
如果有什么不同,我会在 Linux amd64 上运行 GCC(我对此表示怀疑)。
现在,它为什么要警告我呢?这两个函数在common.h 中声明,它包含在sgbd_server.h 中......我在这里缺少什么?
感谢您的宝贵时间!
** 更新 **
谢谢大家的建议。我确实尝试查找在我的包含路径中的其他地方是否会有一个文件common.h 会以某种方式被包含...虽然我没有找到任何会在编译过程中滑倒而不是本地common.h 的文件( sig) 我在我的源文件夹中发现了一些 .ghc 文件。由于make clean 没有清理它们,我手动删除了这些文件。你猜怎么了?没有警告。这些文件是什么?为什么要创建它们?
【问题讨论】:
-
对 sgbd_server.c 中的
#inclde "common.h"有帮助吗? -
我看不出有任何理由。 sgbd_client.c 长什么样子?
-
尝试使用
gcc -E sgbd_server.c来查看预处理器完成后编译的确切内容。 -
@vpit3833,它没有。实际上,如果我这样做,它会抱怨我的结构
Info_FIFO_Transaction被重新定义。 -
@caf,我不太确定如何处理所有转储... :) 在这里:paste2.org/p/1092385
标签: c warnings gcc-warning