gpt4 book ai didi

c - 将 pthread.h 添加到 nds 项目 makefile

转载 作者:行者123 更新时间:2023-11-30 14:45:45 27 4
gpt4 key购买 nike

我已经搜索并尝试将 ARM 项目的库 pthread.h 与我的 makefile 中的 nds 平台链接起来,但仍然无法正确链接它...

#-------------------------------------------------------------------------------
.SUFFIXES:
#-------------------------------------------------------------------------------

ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif

ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPRO")
endif

ifeq ($(strip $(DESMUME)),)
$(error "Please set DESMUME in your environment. export DESMUME=<path to>DeSmuME")
endif

include $(DEVKITARM)/base_rules

#-------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA contains .bin files with extra data for the project (e.g. graphic tiles)
# NITRODATA contains the "virtual" file system accessed through filesystem lib
#-------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include
DATA := data
NITRODATA := nitrofiles

#-------------------------------------------------------------------------------
# options for code generation
#-------------------------------------------------------------------------------
ARCH := -march=armv5te -mlittle-endian

CFLAGS := -Wall -g -O2 \
$(ARCH) -mtune=arm946e-s -fomit-frame-pointer -ffast-math
# -Wall : enable all warnings
# -g : enable debug info generation
# -O2 : code optimization level 2
# $(ARCH) -mtune=arm946e-s : tune code generation for specific machine
# -fomit-frame-pointer : avoid to use a 'frame-pointer' register in functions that do not need it
# -ffast-math : optimize math operations

CFLAGS += $(INCLUDE) -DARM9

ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs $(ARCH)

#-------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#-------------------------------------------------------------------------------
LIBS := -lfilesystem -lfat -lnds9

#-------------------------------------------------------------------------------
# list of directories containing libNDS libraries, this must be the top level
# containing include and lib
#-------------------------------------------------------------------------------
LIBNDS := $(DEVKITPRO)/libnds

#---------------------------------------------------------------------------------
# check if the build directory is not created yet
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT := $(CURDIR)/$(TARGET)

export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)

CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
AFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.bin)))

export OFILES := $(BINFILES:.bin=.o) $(CFILES:.c=.o)
export SFILES := $(AFILES:.s=.o)

# GARLIC_API is the directory where the API's include and source code lives
# (assume a relative structure of the GARLIC project directories)
export GARLICAPI := $(CURDIR)/../GARLIC_API

export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBNDS),-I$(dir)/include) \
-I$(GARLICAPI)

export LIBPATHS := $(foreach dir,$(LIBNDS),-L$(dir)/lib)


#---------------------------------------------------------------------------------
# use CC for linking standard C projects
#---------------------------------------------------------------------------------
export LD := $(CC)


export _ADDFILES := -d $(CURDIR)/$(NITRODATA)


.PHONY: $(BUILD) clean

#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
@echo "Removing ALL intermediate files... "
@echo "Por favor, recuerda que habitualmente NO es necesario hacer un 'clean' antes de un 'make'"
@sleep 3
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds

#---------------------------------------------------------------------------------
run : $(TARGET).nds
@echo "runing $(TARGET).nds with DesmuME"
@$(DESMUME)/DeSmuME.exe $(TARGET).nds &

#---------------------------------------------------------------------------------
debug : $(TARGET).nds $(TARGET).elf
@echo "testing $(TARGET).nds/.elf with DeSmuME_dev/Insight (gdb) through TCP port=1000"
@$(DESMUME)/DeSmuME_dev.exe --arm9gdb=1000 $(TARGET).nds &
@$(DEVKITPRO)/insight/bin/arm-eabi-insight $(TARGET).elf &

#---------------------------------------------------------------------------------
else

DEPENDS := $(OFILES:.o=.d) $(SFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds : $(OUTPUT).elf
$(OUTPUT).elf : $(OFILES) $(SFILES)

#---------------------------------------------------------------------------------
%.nds: %.elf
@ndstool -c $@ -9 $< -b $(GAME_ICON) "$(GAME_TITLE);$(GAME_SUBTITLE1);$(GAME_SUBTITLE2)" $(_ADDFILES)
@echo built ... $(notdir $@)

#---------------------------------------------------------------------------------
%.elf:
@echo linking $(notdir $@)
$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) $(SFILES) -o $@

#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
$(bin2o)

-include $(DEPSDIR)/*.d


#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

由于我不是在Windows环境下工作,目前我找到的线程库如下: enter image description here

总而言之,我的疑问是......我真的不知道如何在我的makefile中链接这个项目中的C线程库......即使我试图在代码中声明该库......就像这个:

#include <pthread.h>

但是类型 pthread_t 未被识别。

这与 makefile 中的链接有关吗?那么我应该添加什么?

最佳答案

Windows DLL 在像 Nintendo DS 这样的嵌入式系统上没有任何用处。您应该只使用为目标平台重建的库,而不是主机系统的库。

此外,像 pthread 这样的东西依赖于操作系统来提供线程服务(通常是 POSIX 兼容的服务),而 Nintendo DS 没有这样的服务:你在裸机上运行,​​并且只有服务这并不意味着不可能在 DS 上进行多线程处理,但这意味着您必须自己完成这一切,使用计时器中断来触发捕获堆栈和程序指针并存储它们的代码某处并恢复上一个线程的那些。这称为软件多线程。

希望,由于 NDS 具有用于视频和音频复用/合成的专用硬件以及用于串行设备通信和网络等慢速任务的从属处理器,因此您的 ARM9 CPU 通常可以自由地不间断地运行游戏逻辑,并且没有多线程的真正需求。

关于c - 将 pthread.h 添加到 nds 项目 makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52805481/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com