Spresense SDK 환경에서 LVM libc++ 표준 라이브러리 사용 방법

최신 NuttX 버전은 Configuration을 통해 LLVM'libc++'C+Standard Library를 선택할 수 있지만 Spresense SDK 환경에서 사용하는 NuttX 버전을 가져오지 않았기 때문에 수동으로 설치해야 합니다.
방법은 LLVM libc++ for NuttX에 쓴 방법을 참고하였다.(혹은 그 자체)

설치하다.


설치 방법은 <Your spresense/nuttx directory>에서 Spresense SDK 환경의nutx 디렉터리를 지정하여 실행install.sh합니다.
$ git clone https://github.com/baggio63446333/libcxx
$ cd libcxx
$ ./install.sh <Your spresense/nuttx directory>
설치라고는 하지만 원본 파일이나 헤더 파일을nutx 이하의 디렉터리로 복사합니다.
  • nuttx/libs/libxx/libcxx
  • nuttx/include/libcxx
  • nuttx/include/machine
  • 이러한 복제 대상의 디렉토리는 .gitignore 파일에 의해 비구성 관리 객체로 설정되므로 git status 명령을 실행해도 표시되지 않습니다.
    파일을 마운트 해제(삭제)할 때 uninstall.sh합니다.
    $ cd libcxx
    $ ./uninstall.sh <Your spresense/nuttx directory>
    

    프로비저닝


    LVM C++Library를 활성화하려면 다음과 같이 Configuuration을 설정합니다.
    열기menuconfig.
    $ cd spresense/sdk
    $ ./tools/config.py default -m
    
    Build Setup -> Customize Header Files ->에서 선택math.h.
    Library Routines ->에서 Standard Math library 사이를 선택합니다.
    Build LLVM libcxx의 설정이 완료되면 설정은 menuconfig 파일로 저장됩니다.
    $ ./tools/mkdefconfig.py feature/libcxx
    
    파일 내용은 다음과 같습니다.
    $ cat configs/feature/libcxx/defconfig 
    -ARCH_MATH_H=y
    -CLOCK_MONOTONIC=y
    +LIBCXX=y
    +LIBCXX_EXCEPTION=n
    +LIBM=y
    
    Makefile을 수정하여 컴파일 옵션을 변경합니다.
  • Inuttx/include/libcxx에 포함 경로 증가
  • -stdc = c++ 98방향 -std=c++ 11 변경
  • -D_NuttX_ 정의 추가
  • 참조: https://github.com/baggio63446333/spresense/commit/06802864c6026ce1caac66da3aca99ea93220810
    $ diff --git a/sdk/tools/scripts/Make.defs b/sdk/tools/scripts/Make.defs
    index 4eb5ddaab5..9f54a50af3 100644
    --- a/sdk/tools/scripts/Make.defs
    +++ b/sdk/tools/scripts/Make.defs
    @@ -49,7 +49,10 @@ ifeq ($(WINTOOL),y)
       DIRUNLINK = $(TOPDIR)/tools/unlink.sh
       MKDEP = $(TOPDIR)/tools/mkwindeps.sh
       ARCHINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" -isystem "${shell cygpath -w $(SDKDIR)/include}"
    -  ARCHXXINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" -isystem "${shell cygpath -w $(TOPDIR)/include/cxx}" -isystem "${shell cygpath -w $(SDKDIR)/include}
    +  ARCHXXINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" -isystem "${shell cygpath -w $(TOPDIR)/include/cxx}" -isystem "${shell cygpath -w $(SDKDIR)/include}"
    +ifeq ($(CONFIG_LIBCXX),y)
    +  ARCHXXINCLUDES += -isystem "${shell cygpath -w $(TOPDIR)/include/libcxx}"
    +endif
       ARCHSCRIPT = -T "${shell cygpath -w $(TOPDIR)/boards/$(CONFIG_ARCH)/$(CONFIG_ARCH_CHIP)/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT)}"
       HOSTEXEEXT = .exe
     else
    @@ -57,6 +60,9 @@ else
       MKDEP = $(TOPDIR)/tools/mkdeps$(HOSTEXEEXT)
       ARCHINCLUDES = -I. -isystem $(TOPDIR)/include -isystem $(SDKDIR)/include
       ARCHXXINCLUDES = -I. -isystem $(TOPDIR)/include -isystem $(TOPDIR)/include/cxx -isystem $(SDKDIR)/include
    +ifeq ($(CONFIG_LIBCXX),y)
    +  ARCHXXINCLUDES += -isystem $(TOPDIR)/include/libcxx
    +endif
       ARCHSCRIPT = -T$(TOPDIR)/boards/$(CONFIG_ARCH)/$(CONFIG_ARCH_CHIP)/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT)
       HOSTEXEEXT =
     endif
    @@ -86,10 +92,10 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
     endif
    
     ARCHCFLAGS = -fno-builtin -mabi=aapcs -ffunction-sections -fdata-sections
    -ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fno-rtti -std=c++98
    +ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fno-rtti -std=c++11
     ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
     ARCHWARNINGSXX = -Wall -Wshadow -Wundef
    -ARCHDEFINES =
    +ARCHDEFINES = -D__NuttX__
     ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
    
     CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe
    

    구축

    configs/feature/libcxx/defconfig의 매개변수에 tools/config.py를 추가하면 LVM C+++Library가 적용됩니다.
    $ cd spresense/sdk
    $ ./tools/config.py feature/libcxx <その他のconfig...>
    $ make
    

    좋은 웹페이지 즐겨찾기