编译csapp.c和csapp.h

标签 c multithreading sockets unix header

我正在尝试编译文件 csapp.ccsapp.h在 Ubuntu 12 操作系统上。我想我缺少一些头文件或一些选项,但我不知道是哪一个。或者也许我没有最新的 gcc。这是我的 Makefile:

SRC = tiny.c
LIB = csapp.c
INC = csapp.h

ALL = $(SRC) $(LIB) $(INC)

webServer-gcc : $(ALL)
    gcc -std=c99 -O2 -lpthread -lrt -o server $(ALL)

这是我从终端输出的错误:

csapp.c: In function ‘Kill’:
csapp.c:81:5: warning: implicit declaration of function ‘kill’ [-Wimplicit-function-    declaration]
csapp.c: In function ‘Signal’:
csapp.c:124:22: error: storage size of ‘action’ isn’t known
csapp.c:124:30: error: storage size of ‘old_action’ isn’t known
csapp.c:127:5: warning: implicit declaration of function ‘sigemptyset’ [-Wimplicit-  function-declaration]
csapp.c:128:23: error: ‘SA_RESTART’ undeclared (first use in this function)
csapp.c:128:23: note: each undeclared identifier is reported only once for each    function it appears in
csapp.c:130:5: warning: implicit declaration of function ‘sigaction’ [-Wimplicit-function-declaration]
csapp.c: In function ‘Sigprocmask’:
csapp.c:138:5: warning: implicit declaration of function ‘sigprocmask’ [-Wimplicit-function-declaration]
csapp.c: In function ‘Sigfillset’:
csapp.c:152:5: warning: implicit declaration of function ‘sigfillset’ [-Wimplicit-function-declaration]
csapp.c: In function ‘Sigaddset’:
csapp.c:159:5: warning: implicit declaration of function ‘sigaddset’ [-Wimplicit-function-declaration]
csapp.c: In function ‘Sigdelset’:
csapp.c:166:5: warning: implicit declaration of function ‘sigdelset’ [-Wimplicit-function-declaration]
csapp.c: In function ‘Sigismember’:
csapp.c:174:5: warning: implicit declaration of function ‘sigismember’ [-Wimplicit-function-declaration]
csapp.c: In function ‘Fdopen’:
csapp.c:326:5: warning: implicit declaration of function ‘fdopen’ [-Wimplicit-function-declaration]
csapp.c:326:13: warning: assignment makes pointer from integer without a cast [enabled by default]
csapp.c: In function ‘open_clientfd’:
csapp.c:741:5: warning: implicit declaration of function ‘bzero’ [-Wimplicit-function-declaration]
csapp.c:743:5: warning: implicit declaration of function ‘bcopy’ [-Wimplicit-function-declaration]
make: *** [webServer-gcc] Error 1

这是我的主函数中最后一个剩余的错误:

tiny.c:23:24: error: storage size of ‘clientaddr’ isn’t known

这是我的代码的第 23 行:

 struct socketaddr_in clientaddr;

最佳答案

使用-std=gnu99,请参阅此link 。 我为您编写了一个新的Makefile,希望这可以帮助您。

CC = gcc
LIBS = -lpthread  -lrt
INCS = -I./
CCFLAGS = -std=gnu99 -O2

all: server
server: csapp.o tiny.c
        $(CC) $(CCFLAGS) $^ -o $@  $(LIBS) $(INCS)
csapp.o: csapp.c csapp.h
        $(CC) $(CCFLAGS) -c $< -o $@  $(INCS)

clean:
        rm -f server csapp.o

关于编译csapp.c和csapp.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11060434/

相关文章:

javascript - jquery:避免过多的递归

java - 套接字关闭前的长时间延迟

java - 内存不足 java 堆大小

谁能告诉我c中的列表文件和映射文件是什么?

Python线程: Threads runs twice?

java线程提前终止并且可疑

c# - 为什么我的Universal App StreamSocket追加了3个空字符?

c - 用 C 访问 AVR 寄存器?

c - 如何从文件中读取数字字符串并将它们放入数组中?

无法将 double 转换为 double