将pthread.h添加到nds项目makefile中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将pthread.h添加到nds项目makefile中相关的知识,希望对你有一定的参考价值。
我已经搜索并尝试将库项目pthread.h链接到我的makefile中的nds platfrom的ARM项目,我仍然无法正确链接它...
#-------------------------------------------------------------------------------
.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环境中工作,我找到的当前线程库是以下的:
总而言之,我的疑问是......我真的不知道如何在我的makefile中链接这个项目中的C库线程...甚至我试图在代码中声明库...像这样:
#include <pthread.h>
但是,无法识别类型pthread_t。
这与makefile中的链接有关吗?在那种情况下,我应该添加什么?
答案
Windows DLL在像Nintendo DS这样的嵌入式系统上没用。您应该只使用为目标平台重建的库,而不是主机系统的库。
此外,像pthread这样的东西依赖于操作系统来提供线程服务(通常是POSIX兼容的),而Nintendo DS没有这样的服务:你是在裸机上运行,而你只有你带来的服务这并不意味着在DS上进行多线程是不可能的,但这意味着你必须自己完成所有工作,使用定时器中断来触发捕获堆栈和程序指针的代码,将它们存储在某处并恢复前一个帖子的那些。这称为软件多线程。
希望由于NDS具有用于视频和音频多路复用/合成的专用硬件以及用于诸如串行设备通信和网络之类的慢速任务的从属处理器,因此您的ARM9 CPU通常可以免费运行您的游戏逻辑并且不需要多线程。
以上是关于将pthread.h添加到nds项目makefile中的主要内容,如果未能解决你的问题,请参考以下文章