Spresense SDK 환경에서 LVM libc++ 표준 라이브러리를 사용하는 방법 (newlib math 편)
math 라이브러리로서 NuttXmath 라이브러리를 사용하는 경우여기.에 썼습니다.
이 글은libc++를 사용합니다. math 라이브러리는 컴파일러 부속 newlib을 사용하는 방법입니다.
TensorFlow Lite를 사용할 때 newlib math를 사용하지 않으면 제대로 작동하지 않기 때문에 부기를 결정했다.
설치하다.
설치 방법은
<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 이하의 디렉터리로 복사합니다..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
Library Routines ->
부터 체크Build LLVM libcxx
합니다.menuconfig
의 설정이 완료되면 설정은 configs/feature/libcxx/defconfig
파일로 저장됩니다.$ ./tools/mkdefconfig.py feature/libcxx
파일 내용은 다음과 같습니다.$ cat configs/feature/libcxx/defconfig
-CLOCK_MONOTONIC=y
+LIBCXX=y
+LIBCXX_EXCEPTION=n
이 설정만 있으면 컴파일 오류가 발생하기 때문에 컴파일러 부속 <cmath>
을 포함시키기 위해서 nuttx/include/cxx/cmath
#includenext 줄을 추가합니다.CONFIG_ARCH_MATH_H
의 정의 여부에 따라 처리를 구분합니다.$ diff -u nuttx/include/cxx/cmath{.org,}
--- nuttx/include/cxx/cmath.org
+++ nuttx/include/cxx/cmath
@@ -43,6 +43,10 @@
#include <nuttx/config.h>
#include <nuttx/compiler.h>
+#ifdef CONFIG_ARCH_MATH_H
+# include_next <cmath>
+#else
+
#include <math.h>
//***************************************************************************
@@ -136,4 +140,5 @@
}
+#endif // CONFIG_ARCH_MATH_H
#endif // __INCLUDE_CXX_CMATH
arm-none-eabi-gcc의 버전에 따라 컴파일러가 첨부한 std_abs.h
는 표준<stdlib.h>
을 포함하고 다중 정의에서 욕을 먹기 때문에 NuttX측의 헤더 파일을 자주 참조해야 한다.$ diff -u /Users/xxx/spresenseenv/usr/arm-none-eabi/include/c++/7.3.1/bits/std_abs.h{.org,}
--- /Users/xxx/spresenseenv/usr/arm-none-eabi/include/c++/7.3.1/bits/std_abs.h.org
+++ /Users/xxx/spresenseenv/usr/arm-none-eabi/include/c++/7.3.1/bits/std_abs.h
@@ -35,7 +35,7 @@
#include <bits/c++config.h>
#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
-#include_next <stdlib.h>
+#include <stdlib.h>
#ifdef __CORRECT_ISO_CPP_MATH_H_PROTO
# include_next <math.h>
#endif
Makefile을 수정하여 컴파일 옵션을 변경합니다.$ 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
구축
tools/config.py
의 매개변수에 feature/libcxx
를 추가하면 LVM C+++Library가 적용됩니다.$ cd spresense/sdk
$ ./tools/config.py feature/libcxx <その他のconfig...>
$ make
Reference
이 문제에 관하여(Spresense SDK 환경에서 LVM libc++ 표준 라이브러리를 사용하는 방법 (newlib math 편)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/baggio/items/1944157e0ff3474a962e텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)