我有这个问题与C线程:我已经包含cpu.h到主文件,为什么这个错误持续存在??
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 '未声明(在此函数中首次使用)
我在main.c中包含了cpu.h
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
您已经从另一个包含文件"funzioni.h"中复制了包含保护。
将其更改为CPU_H
或类似的
我猜cpu.h #ifndef FUNZIONI_H
中的include-guard已经在其他地方定义了