我有C线程的这个问题: 我把cpu.h包含到主文件中,为什么这个错误仍然存在?
的main.c
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include "funzioni.h"
#include "ram.h"
#include "cpu.h"
#include "err.h"
......
......
rc = pthread_create (&threads[i] , NULL ,cpu, (void*)¶metri_thread_cpu[i] );
错误:'cpu'未声明(首次使用此功能)
我将cpu.h包含到main.c
中cpu.h
#ifndef FUNZIONI_H
#define FUNZIONI_H
void *cpu(void *thread_arg);
#endif
我的Makefile
# Sources
SRCS= err.c funzioni.c cpu.c ram.c main.c
OBJS=$(SRCS:.c=.o)
EXECUTABLE=main.x
# Config
CC=gcc
CFLAGS= -c
LIBS= -lpthread
LD=gcc
# Target
all: clean $(EXECUTABLE)
clean:
@echo Cleaning old files
@rm -f *.o *.x
$(EXECUTABLE): $(OBJS)
@echo -------------Building $@
@ $(LD) -o $@ $^ $(LIBS)
err.o: err.c err.h
@echo -------------Building $@
@ $(CC) $(CFLAGS) -o $@ $<
funzioni.o: funzioni.c funzioni.h
@echo -------------Building $@
@ $(CC) $(CFLAGS) -o $@ $< $(LIBS)
cpu.o: cpu.c cpu.h funzioni.h err.h
@echo -------------Building $@
@ $(CC) $(CFLAGS) -o $@ $< $(LIBS)
ram.o: ram.c ram.h funzioni.h err.h
@echo -------------Building $@
@ $(CC) $(CFLAGS) -o $@ $< $(LIBS)
main.o: main.c ram.h cpu.h funzioni.h err.h
@echo -------------Building $@
@ $(CC) $(CFLAGS) -o $@ $< $(LIBS)
.PHONY: all clean
这是我编译代码的makefile
答案 0 :(得分:1)
您已从其他包含文件中复制了包含警戒,&#34; funzioni.h&#34;。
将其更改为CPU_H
或类似内容。
答案 1 :(得分:0)
我猜cpu.h #ifndef FUNZIONI_H
中的include-guard已在其他地方定义。