c - 线程创建 : error error: ‘cpu’ undeclared (first use in this function)

标签 c multithreading

我在使用 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*)&parametri_thread_cpu[i] );

错误:“cpu”未声明(在此函数中首次使用)

我将 cpu.h 包含到 main.c 中

cpu.h

#ifndef FUNZIONI_H
#define FUNZIONI_H
void *cpu(void *thread_arg);
#endif

我的生成文件

# 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或类似的。

关于c - 线程创建 : error error: ‘cpu’ undeclared (first use in this function),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24327993/

相关文章:

java - 不同的线程是否看到局部变量引用的相同版本的对象?

c - 在链表中使用 free() 的 Valgrind 错误

c - C 中的 fork() 和 exec() 函数

c - 使用 gdb 调试正在运行的守护进程

java - 你可以在 Java play 框架中使用多线程吗?

multithreading - ColdFusion/Railo 组件线程化 http 请求

c - 将 C 代码转换为 MIPS 汇编代码

c - 使用级联 "else if"语句有什么缺点吗?

c++ - 如何在 C++ 中测试条件变量?

java - 如何让连接线程保持 Activity 状态? (我需要使用守护进程吗?)