在STM32MP1 A7内核上交叉编译CppUTest(单元测试工具)

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

我正在开发一个针对 STM32MP1 Cortex-A7 处理器的项目,并尝试将 CppUTest 框架集成到我的构建过程中。我正在使用 VirtualBox Linux 交叉编译我的代码。我的开发环境设置了用于交叉编译的特定工具链,通过获取 SDK 提供的脚本来激活:

source /opt/poky-bytesatwork/3.2.2/environment-setup-cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi

我的项目有一个 Makefile,我需要在这个 Makefile 中包含 CppUTest 库的编译。这是我的 Makefile 设置的相关部分:

CXX ?= g++
APP = stb
BIN = bin/
GIT_REVISION := $(shell git describe --abbrev=10 --dirty --always)
INCLUDE = -ICommandInterface -ICommon -IDataHandling -IFakeDevices -IHardwareInterface \
          -ILocalTest -ILocalTest/Tests -ILocalTest/Tests/A7tests -ILocalTest/CppUTest/include
SOURCE_FILES = CommandInterface/CommandInterface.cpp \
               Common/Main.cpp \
               Common/MainHandler.cpp \
               Common/ObjectHandler.cpp \
               ...etc

CPPUTEST_LIB_DIR = LocalTest/CppUTest/lib

$(APP): $(BIN)
    $(CXX) -Wall -g -O2 -pthread -DGIT_REVISION=\"$(GIT_REVISION)\" -o $(BIN)$(APP) $(INCLUDE) $(SOURCE_FILES) -Wno-unknown-pragmas -L$(CPPUTEST_LIB_DIR) -lCppUTest -lCppUTestExt

$(BIN):
    @mkdir -p $(BIN)

我不确定如何使用源环境指定的交叉编译器正确编译 CppUTest 库。我的目标是:

确保 CppUTest 使用正确的交叉编译器进行编译。

问题:

如何在构建应用程序之前调整我的 Makefile(或 CppUTest Makefile)以使用交叉编译器自动编译 CppUTest?

我尝试使用以下命令配置 CppUTest 项目以进行交叉编译:

./configure --host=arm-poky-linux-gnueabi-g++

但是,在为我的交叉编译器指定了 --host 选项运行 ./configure 命令后,编译失败并出现以下错误:

checking host system type... Invalid configuration `arm-poky-linux-gnueabi-g++': more than four components

configure: error: /bin/bash ././config.sub arm-poky-linux-gnueabi-g++ failed
c++ linux stm32 cross-compiling cpputest
1个回答
0
投票

我的方法不会改变 Makefile,但仍然可以正常工作。

使用 bash 创建一个构建脚本,该脚本首先执行以下操作,然后执行 Makefile。在 Makefile 中您可以使用创建的库。

  1. 创建项目目录。
  2. 按照 GitHub 存储库中的说明将 CppUTest 下载到项目目录中。
  3. 在项目目录中创建一个名为“toolchain.cmake”的文件。
  4. 将以下代码粘贴到新创建的文件中并填写以下样板:
set(CMAKE_CXX_COMPILER path/to/your/compiler)
set(CMAKE_C_COMPILER path/to/your/compler)
#you also need settings for includes for the include files and source code
#the next line is compiler dependent, check your manual for flag placement
#it gives the strucuture on the command line for CMake on how to use the #syntax of your compiler to compile a CXX object file
set(CMAKE_CXX_COMPILE_OBJECT this_is_your_time_to_shine_:_compiler_command_) 
#the next 4 lines surpress CMake inner checkings for supported compilers
set(CMAKE_C_COMPILER_FORCED TRUE CACHE INTERNAL "")
set(CMAKE_CXX_COMPILER_FORCED TRUE CACHE INTERNAL "")
set(CMAKE_C_COMPILER_ID_RUN TRUE CACHE INTERNAL "")
set(CMAKE_CXX_COMPILER_ID_RUN TRUE CACHE INTERNAL "")
#the next for lines print you out if your compiler is being used:
message(STATUS "Using C compiler: ${CMAKE_C_COMPILER}")
message(STATUS "Using C++ compiler: ${CMAKE_CXX_COMPILER}")
  1. 现在按照 CppUTest GitHub 存储库的说明生成 cpputest-build 目录。
  2. 之后进入提到的目录。
  3. 删除其中所有内容。
  4. 执行
    sudo cmake -DCMAKE_TOOLCHAIN_FILE=absolute/path/to/your/toolchain.cmake ../cpputest-src
  5. 执行
    sudo make
  6. 会失败,通过修改cpputest的源码使其可以工作。
  7. 再次执行步骤 3 至 5,一遍又一遍,直到成功为止。
  8. 成功后,您将在 CMakeFiles/ 目录中的某个位置获得目标文件
  9. 使用编译器工具链归档器/libcreater 创建一个库。
  10. 使用库编译您的测试用例。

现在编写 bash 脚本并执行它。你完成了。极好的。希望能有点帮助。

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