我正在开发一个针对 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
我的方法不会改变 Makefile,但仍然可以正常工作。
使用 bash 创建一个构建脚本,该脚本首先执行以下操作,然后执行 Makefile。在 Makefile 中您可以使用创建的库。
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}")
sudo cmake -DCMAKE_TOOLCHAIN_FILE=absolute/path/to/your/toolchain.cmake ../cpputest-src
sudo make
现在编写 bash 脚本并执行它。你完成了。极好的。希望能有点帮助。