Before discussing the issues in this article, let’s first talk about a topic: “Currently, CP Autosar supports Some/IP and DDS (Data Distribution Service). DDS seems just another protocol; is it really necessary to implement DDS in vehicles?” Regarding this question, I would like to share my personal understanding. In CP Autosar, Some/IP appeared earlier, and as of now, it should already be present in mass-produced models. It can be said that Some/IP is tailor-made for automobiles. On the other hand, DDS has been applied in other industrial control fields for a long time, but in recent years, with the development of automotive intelligence, especially the application of new technologies like domain control, DDS has gradually expanded into the automotive field. If vehicles are to become part of the Internet of Everything, I am more optimistic about DDS. Compared to Some/IP, the DDS protocol has already been applied in other industrial control fields, making the realization of the Internet of Everything easier. In this sense, DDS not only enriches QoS compared to Some/IP, but it can also better connect to the Internet of Everything. Of course, this does not mean that Some/IP will be abandoned; during the vehicle design phase, different solutions will be chosen based on different scenarios rather than using a single solution exclusively.
1. What is Cross-Compilation?
Returning to the main topic, I am currently porting eProsima Fast DDS to the target machine: the Xilinx G9H. The development environment used is Ubuntu 20.04. As can be seen, even if an executable file is compiled using the default compilation on Ubuntu 20.04, it will not run on the G9H due to the different architectures and running instructions. Ubuntu 20.04 corresponds to x86_64, while G9H corresponds to Arm aarch64.
Therefore, to compile an executable file that can run on G9H in the Ubuntu 20.04 environment, it is necessary to install the toolchain corresponding to the target machine in the Ubuntu 20.04 environment to compile an executable file that the target machine can run. This is what we commonly refer to as “cross-compilation.”
2. Writing the Makefile
-
Select the appropriate compiler toolchain for G9H; -
Link to the Arm aarch64 architecture’s eProsima Fast DDS dynamic library. This article takes HelloWorld as an example, and the file structure is as follows (partially), with the goal of compiling an executable file that can run on the Arm platform.
(1) Makefile Content
# Specify compiler pathCROSS_COMPILE = /tool/gcc_linaro/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc# GNU assemblerAS = $(CROSS_COMPILE)as# GNU linkerLD = $(CROSS_COMPILE)ldCXX = $(CROSS_COMPILE)g++# Utility for creating, modifying and extracting archivesAR = $(CROSS_COMPILE)ar# List symbols in object filesNM = $(CROSS_COMPILE)nm # Discard symbolsSTRIP = $(CROSS_COMPILE)strip # Copy and convert target filesOBJCOPY = $(CROSS_COMPILE)objcopy# Display information about object filesOBJDUMP = $(CROSS_COMPILE)objdump export AS LD CXX AR NMexport STRIP OBJCOPY OBJDUMP
CFLAGS +=-I. -g -O0 -Wall -DUSE_LINUX -D__YOCTO_G2D_TEST__ -fpermissive CPPFLAGS := -g -O0 -Wall -Wno-reorder -std=c++11 -fpermissive -fPIC# –L -l (uppercase L specifies dynamic library path, lowercase l specifies dynamic library name), PWD indicates current pathLDFLAGS += -lstdc++ -lpthread -fPIC -L. -L${PWD}/fastdds_dep/lib \ -l:libfastcdr.so \ -l:libfastcdr.so.1 \ -l:libfastcdr.so.1.0.27 \ -l:libfastrtps.so \ -l:libfastrtps.so.2.10 \ -l:libfastrtps.so.2.10.0 \ -l:libfoonathan_memory-0.7.3.so \ -l:libtinyxml2.so \ -l:libtinyxml2.so.9 \ -l:libtinyxml2.so.9.0.0 INCLUDE := \ -I ./ \ -I${PWD}/fastdds_dep/ \ -I${PWD}/fastdds_dep/include/ \ -I${PWD}/fastdds_dep/include/fastcdr/ \ -I${PWD}/fastdds_dep/include/fastcdr/exceptions/ \ -I${PWD}/fastdds_dep/include/fastdds/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/builtin/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/builtin/common/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/builtin/topic/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/builtin/typelookup/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/builtin/typelookup/common/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/common/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/core/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/core/condition/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/core/policy/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/core/status/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/domain/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/domain/qos/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/log/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/publisher/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/publisher/qos/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/subscriber/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/subscriber/qos/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/topic/ \ -I${PWD}/fastdds_dep/include/fastdds/dds/topic/qos/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/attributes/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/builtin/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/builtin/data/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/builtin/discovery/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/builtin/discovery/endpoint/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/builtin/discovery/participant \ -I${PWD}/fastdds_dep/include/fastdds/rtps/builtin/liveliness/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/common/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/exceptions/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/flowcontrol/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/history/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/interfaces/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/messages/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/network/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/participant/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/reader/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/resources/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/security/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/security/accesscontrol/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/security/authentication/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/security/common/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/security/cryptography/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/security/exceptions/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/security/logging/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/transport/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/shared_mem/ \ -I${PWD}/fastdds_dep/include/fastdds/rtps/writer/ \ -I${PWD}/fastdds_dep/include/fastdds/statistics/ \ -I${PWD}/fastdds_dep/include/fastdds/statistics/dds/ \ -I${PWD}/fastdds_dep/include/fastdds/statistics/dds/domain/ \ -I${PWD}/fastdds_dep/include/fastdds/statistics/dds/publisher/ \ -I${PWD}/fastdds_dep/include/fastdds/statistics/dds/publisher/qos/ \ -I${PWD}/fastdds_dep/include/fastdds/statistics/dds/subscriber/ \ -I${PWD}/fastdds_dep/include/fastdds/statistics/dds/subscriber/qos/ \ -I${PWD}/fastdds_dep/include/fastdds/statistics/rtps/ \ -I${PWD}/fastdds_dep/include/fastdds/thirdparty/optionparser/ \ -I${PWD}/fastdds_dep/include/fastdds/thirdparty/optionparser/optionpars \ -I${PWD}/fastdds_dep/include/fastrtps/ \ -I${PWD}/fastdds_dep/include/fastrtps/attributes/ \ -I${PWD}/fastdds_dep/include/fastrtps/common/ \ -I${PWD}/fastdds_dep/include/fastrtps/config/ \ -I${PWD}/fastdds_dep/include/fastrtps/log/ \ -I${PWD}/fastdds_dep/include/fastrtps/participant/ \ -I${PWD}/fastdds_dep/include/fastrtps/publisher/ \ -I${PWD}/fastdds_dep/include/fastrtps/qos/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/attributes/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/builtin/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/builtin/data/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/builtin/discovery/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/builtin/discovery/endpoint/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/builtin/discovery/participant \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/builtin/liveliness/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/common/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/exceptions/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/flowcontrol/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/history/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/messages/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/network/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/participant/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/reader/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/resources/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/security/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/security/accesscontrol/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/security/authentication/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/security/common/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/security/cryptography/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/security/exceptions/ \ -I${PWD}/fastdds_dep/include/fastrtps/rtps/writer/ \ -I${PWD}/fastdds_dep/include/fastrtps/subscriber/ \ -I${PWD}/fastdds_dep/include/fastrtps/transport/ \ -I${PWD}/fastdds_dep/include/fastrtps/types/ \ -I${PWD}/fastdds_dep/include/fastrtps/utils/ \ -I${PWD}/fastdds_dep/include/fastrtps/utils/collections/ \ -I${PWD}/fastdds_dep/include/fastrtps/xmlparser/ \ -I${PWD}/fastdds_dep/include/foonathan_memory/foonathan/memory/ \ -I${PWD}/fastdds_dep/include/foonathan_memory/foonathan/memory/detail/
# Generate target file, named HelloWorldTARGETS = HelloWorld# Place all files ending with .cpp in the current folder into the SRC_CPP variableSRC_CPP=$(wildcard *.cpp)# Place all files ending with .cxx in the current folder into the SRC_CXX variableSRC_CXX=$(wildcard *.cxx)# Replace the .cpp suffix in the SRC_CPP variable with .o and assign to the APP_CPP_OBJS variableAPP_CPP_OBJS=$(SRC_CPP:.cpp=.o)# Replace the .cxx suffix in the SRC_CXX variable with .o and assign to the APP_CXX_OBJS variableAPP_CXX_OBJS=$(SRC_CXX:.cxx=.o)
all: $(TARGETS)# Output APP_CXX_OBJS information @echo $(APP_CXX_OBJS)# -g executable program includes debugging informationHelloWorld: $(APP_CPP_OBJS) $(APP_CXX_OBJS) $(CXX) $(LDFLAGS) $(CPPFLAGS) $(INCLUDE) -o $(TARGETS) -g $(APP_CPP_OBJS) $(APP_CXX_OBJS) $(LDLIBS) -lpthread -lfastcdr -lfastrtps -lfoonathan_memory-0.7.3 -ltinyxml2
#$@--target file, $^--all dependency files, $<--first dependency file# -c compile only without linking. Produce .o files, do not produce executable files; -o specifies output file name%.o: %.cpp $(CXX) -c $(CFLAGS) $(INCLUDE) $(CPPFLAGS) -o $@ $<%.o: %.cxx $(CXX) -c $(CFLAGS) $(INCLUDE) $(CPPFLAGS) -o $@ $<
clean: rm -rf $(TARGETS) *.o
-
The CROSS_COMPILE specifies the compiler path to use for cross-compilation; otherwise, it will use the default compiler, which will not produce the expected executable file; -
The beginning of each command must be separated by the TAB key, not spaces; otherwise, during make, it will prompt “*** missing separator. Stop” as shown below:
-
The source files in this article need to use the eProsima Fast DDS dynamic library, and the eProsima Fast DDS dynamic library (which has been pre-compiled for the corresponding architecture) needs to be ARM aarch64 architecture to effectively link when generating the executable file, thereby generating the corresponding executable file for the target machine. The dynamic libraries required for this article (ARM aarch64 format) are as follows:
You can use the command: file dynamic_library_name to confirm whether the dynamic library matches, as shown in the example below:
Reference Links
Previous Highlights Review
Summary of previous excellent articles on Autosar: 151~200
Embedded Development: How to Identify PowerOn Wake-up and Bus Wake-up
In the office, memories cannot be retained
How to Understand KL15 and PORST Pin
Installation Pitfalls of eProsima Fast DDS
Embedded Development: Interpretation of MCU Power On and Off
Embedded Development: Understanding Periodic Scheduling and Code Execution Time
Embedded Development: Developing Based on CMake in VSCode
Bootloader Development: Why is SBL (Secondary Bootloader) Needed?
Fast/Slow Recovery Mechanism After Bus Off
Open Source Fast-DDS Installation Example and DDS Model Architecture
Overview of DDS and DCPS Model
Cross-compiling C and C++ Based on CMake
TRACE32: Multi-core Debugging Configuration
Autosar EcuM: A Brief Analysis of APP from RUN to POST_RUN
Autosar Network Management: Can CAN FD Frames Wake Up the Network?
Embedded Development: WWD of TLF35584 External Dog
Embedded Development: How to Understand ECU Wake-up, Sleep, and Reset?
Basics of C Language: The Use of do{…}while(0), Quite Elegant
Autosar EcuM: ECU Start and Stop Process
Embedded Development: Enabling Cached Functionality Leads to Data Consistency Issues
Click below to follow, let’s talk about Autosar/embedded systems together. If needed, contact the author to join the group for more professional answers.