如何配置xtensa-lx106-elf使用nonos-sdk为esp8266编译c++代码?

问题描述 投票:0回答:2

我在使用 xtensa-lx106-elf 编译 C++ 代码时遇到困难。

我使用的芯片(esp8266)的制造商提供了一个sdk(nonos-sdk)。 该sdk中的库之一实现了在芯片中分配内存的函数:os_mallocos_realloc

编译 c 代码时,一切正常。编译 c++ 时,目标文件已成功生成,但我从链接器收到很多错误消息,抱怨对 abortfreemalloc 的未定义引用以及对 __gxx_personality_v0 的非常奇怪的引用。

我的 make 文件是使用 cmake 创建的。下面是我与编译器一起使用的选项。

target_include_directories( 
  ${elf_file}

  PUBLIC
  src/
  inc/
  /opt/esp-open-sdk/sdk/driver_lib/include/
  /opt/esp-open-sdk/sdk/include/
  )

target_compile_options(
  ${elf_file}

  PUBLIC
  -mlongcalls -c -std=c++11 -v
  )

target_link_libraries( 
  ${elf_file}

  PUBLIC

  -L/opt/esp-open-sdk/sdk/lib
  -L/opt/esp-open-sdk/sdk/ld
  -Teagle.app.v6.ld

  -nostdlib

  -Wl,--start-group
    -lmain -lhal -lnet80211 -lcrypto -lupgrade -lwpa -llwip -lpp -lphy -v
  -Wl,--end-group

  -ldriver
  -lcirom
  -lgcc
  )

编译器错误:

CMakeFiles/MasterSPI-esp8266.elf.dir/src/main.cpp.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
CMakeFiles/MasterSPI-esp8266.elf.dir/src/spi.cpp.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2.o):(.literal+0x8): undefined reference to `abort'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2.o): In function `execute_cfa_program':
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-dw2.c:1212: undefined reference to `abort'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2.o): In function `read_encoded_value_with_base':
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-pe.h:252: undefined reference to `abort'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2.o): In function `execute_stack_op':
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-dw2.c:905: undefined reference to `abort'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2.o): In function `uw_update_context_1':
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-dw2.c:1420: undefined reference to `abort'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2.o):/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-dw2.c:1560: more undefined references to `abort' follow
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2-fde.o):(.literal+0x20): undefined reference to `malloc'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2-fde.o):(.literal+0x24): undefined reference to `free'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2-fde.o): In function `size_of_encoded_value':
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-pe.h:88: undefined reference to `abort'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2-fde.o): In function `read_encoded_value_with_base':
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-pe.h:257: undefined reference to `abort'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2-fde.o): In function `base_from_object':
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-dw2-fde.c:256: undefined reference to `abort'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2-fde.o): In function `start_fde_sort':
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-dw2-fde.c:409: undefined reference to `malloc'
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-dw2-fde.c:412: undefined reference to `malloc'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2-fde.o): In function `end_fde_sort':
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-dw2-fde.c:575: undefined reference to `abort'
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-dw2-fde.c:590: undefined reference to `free'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2-fde.o): In function `__register_frame':
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-dw2-fde.c:118: undefined reference to `malloc'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2-fde.o): In function `__register_frame_table':
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-dw2-fde.c:156: undefined reference to `malloc'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2-fde.o): In function `__deregister_frame_info_bases':
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-dw2-fde.c:200: undefined reference to `free'
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-dw2-fde.c:216: undefined reference to `abort'
/opt/esp-open-sdk/sdk/lib/libgcc.a(unwind-dw2-fde.o): In function `__deregister_frame':
/home/wjg/Repo/esp-open-sdk-20170622/crosstool-NG/.build/src/gcc-4.8.5/libgcc/unwind-dw2-fde.c:231: undefined reference to `free'

引起我注意的是,链接器似乎试图在路径中找到许多文件:“/home/wjg/Repo/”,我可以确认它在我的计算机中不存在。无法理解这种行为。


工具信息:

操作系统:Ubuntu 16.04LTS

编译器:xtensa-lx106-elf-g++(crosstool-NG crosstool-ng-1.22.0-60-g37b07f6)4.8.5

CMake:cmake 版本 3.12.0-rc3

nonos-sdk:2.2.1

c++11 cmake sdk esp8266 xtensa
2个回答
1
投票

也许您忘记链接 C++ 库?这些是我在 ESP8266 上链接 C++ 文件时使用的库:

-lhal -lphy -lpp -lnet80211 -llwip2 -lwpa -lcrypto -lmain -lwps \
-laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 -lstdc++ -lm -lc -lgcc

尤其是 -lstdc++ 很重要!尝试将这些库添加到您的 makefile 中!


0
投票

您可能正在导入 stdlib 或尝试使用 malloc、free 和其他一些 stdlib 函数,这些函数在此 SDK 中不可用。

将所有使用 malloc() 的地方重命名为 os_zalloc(),然后重试。

当源指向或导入标准库时,通常会发生这种情况。你的编译器标志告诉你原因:-nostdlib

© www.soinside.com 2019 - 2024. All rights reserved.