Create x-compile_commands
Table of Contents
Overview
When cross-compiling for example with a Yocto
sdk, most of the time
we are using some kind of gcc
with different flags. The flags are
set when sourcing the environment script, and is stuck during the
session. This is all fine, unfortunately this setup makes it hard to
use any clang-tools
which are available, which are great for both
verification and for formatting code and many other things.
Most of the time the clang tools (e.g clang-tidy ) needs to be able to
read the compile_commands.json
file, to be able perform its task.
The compile_commands
file as its name suggests consists of commands
how the project-files are compiled into object code for each translation unit.
The compile_commands.json
can be generated in many different way
(e.g cmake, bear …),
but for this exercises I will stick to using cmake with the build
command -DCMAKE_EXPORT_COMPILE_COMMANDS=1
which will generate a
compile_commands.json
in the build directory. This document will try
to explain how to generate a compile_commands.json
switching out
the arm-gcc
with clang and provide and exclude flags which are not
synchronized between clang and gcc. I will be using only c++,
the same should work for c.
Lets dive right into it.
Building, generating compile_commands.json
The first task would be to setup the environment for cross-compiling by sourcing the yocto-environment.
source /opt/ocp/13.4.1/environment-setup-cortexa7t2hf-neon-poky-linux-gnueabi
We can now inspect the CXX
and CXXFLAGS
in the environment. This
will be useful later on.
echo $CXX arm-poky-linux-gnueabi-g++ -march=armv7ve -mthumb -mfpu=neon \ -mfloat-abi=hard -mcpu=cortex-a7 \ --sysroot=/opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi echo $CXXFLAGS -O2 -pipe -g -feliminate-unused-debug-types
Then its time start building the project with cmake
but provide the
generation of compile_commands
e.g
cd src/project && mkdir build && cd build cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 .. . . . .
This will generate the auxiliary cmake files and cache together with
the make
and compile_commands.json
.
Compile commands
If we start inspecting the compile_commands.json
we notice that
its a json list with a structure.
.eg
[ { "directory": "/home/ocp/src/cpp1/darf/build/src/service", "command": "arm-poky-linux-gnueabi -march=armv7ve....... -std=gnu++17 -o main.cpp.o -c main.cpp", "file": "/home/ocp/src/cpp1/darf/src/service/main.cpp" } ]
If you want to parse the structure you can always use the quicktype excellent code generation for json structures. But for this exercise its not necessary.
Trying it out
The first task is to see what happens if we just grab one of the
compile commands from the file and just replace the compiler
(arm-poky-linux-gnueabi
) with clang++
and see what happens
So from the compile_commands.json
I grab one command,
CMD="/opt/ocp/13.4.1/sysroots/x86_64-ocpsdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -march=armv7ve -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi --sysroot=/opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi -DBOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION -DBOOST_ENABLE_ASSERT_HANDLER -I/home/ocp/src/cpp1/eden/include -I/home/ocp/src/cpp1/eden/src/adam/include -I/home/ocp/src/cpp1/eden/src/serpent/include -I/home/ocp/user_sysroots/13.4.1/usr/include -I/home/ocp/src/cpp1/eden/gen_files -I/home/ocp/src/cpp1/eden/src/adam/../include -O2 -pipe -g -feliminate-unused-debug-types -Wno-psabi -Wno-maybe-uninitialized -Wall -Wextra -pedantic -funsigned-char -std=gnu++17 -o CMakeFiles/adam_app.dir/src/main.cpp.o -c /home/ocp/src/cpp1/eden/src/adam/src/main.cpp" compile=$(echo ${CMD} | sed s#/opt/ocp/13.4.1/sysroots/x86_64-ocpsdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++#clang++#) echo ${compile}
OK, if we run this we get
eval ${compile} clang: warning: argument unused during compilation: '-mthumb' [-Wunused-command-line-argument] clang: warning: argument unused during compilation: '-mfpu=neon' [-Wunused-command-line-argument] clang: warning: argument unused during compilation: '-mfloat-abi=hard' [-Wunused-command-line-argument] clang: warning: argument unused during compilation: '-mcpu=cortex-a7' [-Wunused-command-line-argument] warning: unknown warning option '-Wno-psabi' [-Wunknown-warning-option] warning: unknown warning option '-Wno-maybe-uninitialized'; did you mean '-Wno-uninitialized'? [-Wunknown-warning-option] error: unknown target CPU 'armv7ve' note: valid target CPU values are: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cannonlake, icelake-client, icelake-server, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, x86-64
If we ignore the warnings for the time being and focus on the errors,
we can see that there is something wrong with specifying the target
architecture. The problem is that clang is using different flags to
get this to work, what we need is the clang version of
cross-compiling. This information can be found at
clang cross compile web site. So instead of using the -march...
we
need to provide the clang triple which in my case is
--target=armv7e-unknown-linux-elf
So lets replace the -march=armv7ve
flag with clangs equivalent
(--target=armv7e-unknown-linux-elf
)
CMD="/opt/ocp/13.4.1/sysroots/x86_64-ocpsdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -march=armv7ve -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi --sysroot=/opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi -DBOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION -DBOOST_ENABLE_ASSERT_HANDLER -I/home/ocp/src/cpp1/eden/include -I/home/ocp/src/cpp1/eden/src/adam/include -I/home/ocp/src/cpp1/eden/src/serpent/include -I/home/ocp/user_sysroots/13.4.1/usr/include -I/home/ocp/src/cpp1/eden/gen_files -I/home/ocp/src/cpp1/eden/src/adam/../include -O2 -pipe -g -feliminate-unused-debug-types -Wno-psabi -Wno-maybe-uninitialized -Wall -Wextra -pedantic -funsigned-char -std=gnu++17 -o CMakeFiles/adam_app.dir/src/main.cpp.o -c /home/ocp/src/cpp1/eden/src/adam/src/main.cpp" compile=$(echo ${CMD} | sed s#/opt/ocp/13.4.1/sysroots/x86_64-ocpsdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++#clang++#) compile=$(echo ${compile} | sed s/-march=armv7ve/--target=armv7e-unknown-linux-elf/) echo ${compile}
Now the output file is not really what I want so will replace that with something better.
So lets extend the substitution.
CMD="/opt/ocp/13.4.1/sysroots/x86_64-ocpsdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -march=armv7ve -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi --sysroot=/opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi -DBOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION -DBOOST_ENABLE_ASSERT_HANDLER -I/home/ocp/src/cpp1/eden/include -I/home/ocp/src/cpp1/eden/src/adam/include -I/home/ocp/src/cpp1/eden/src/serpent/include -I/home/ocp/user_sysroots/13.4.1/usr/include -I/home/ocp/src/cpp1/eden/gen_files -I/home/ocp/src/cpp1/eden/src/adam/../include -O2 -pipe -g -feliminate-unused-debug-types -Wno-psabi -Wno-maybe-uninitialized -Wall -Wextra -pedantic -funsigned-char -std=gnu++17 -o CMakeFiles/adam_app.dir/src/main.cpp.o -c /home/ocp/src/cpp1/eden/src/adam/src/main.cpp" compile=$(echo ${CMD} | sed s#/opt/ocp/13.4.1/sysroots/x86_64-ocpsdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++#clang++#) compile=$(echo ${compile} | sed -e 's/-march=armv7ve/--target=armv7e-unknown-linux-elf/' -e 's/-o.*.cpp.o /-o test.o /' ) echo $compile
and if we now run the compile command we get
eval $compile warning: unknown warning option '-Wno-psabi' [-Wunknown-warning-option] warning: unknown warning option '-Wno-maybe-uninitialized'; did you mean '-Wno-uninitialized'? [-Wunknown-warning-option] In file included from /home/ocp/src/cpp1/eden/src/adam/src/main.cpp:3: In file included from /opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/boost/asio.hpp:20: In file included from /opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/boost/asio/async_result.hpp:18: In file included from /opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/boost/asio/detail/config.hpp:26: In file included from /opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/boost/config.hpp:44: /opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/boost/config/select_stdlib_config.hpp:18:12: fatal error: 'cstddef' file not found # include <cstddef> ^~~~~~~~~ 2 warnings and 1 error generated.
This is what we wanted, we almost got it to work, we are still having some warnings, but we will fix them. We could not find the system includes, so we need to add them. But lets first check out the warnings.
Fix Warnings
Ok we still have some warnings that needs to be handled.
We start with the -Wno-psabi
which seems to be a flag that is not
supported in clang, the -Wno-maybe-uninitialized
also seems to be a
warning that is not supported by clang. So lets remove them both.
CMD="/opt/ocp/13.4.1/sysroots/x86_64-ocpsdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -march=armv7ve -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi --sysroot=/opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi -DBOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION -DBOOST_ENABLE_ASSERT_HANDLER -I/home/ocp/src/cpp1/eden/include -I/home/ocp/src/cpp1/eden/src/adam/include -I/home/ocp/src/cpp1/eden/src/serpent/include -I/home/ocp/user_sysroots/13.4.1/usr/include -I/home/ocp/src/cpp1/eden/gen_files -I/home/ocp/src/cpp1/eden/src/adam/../include -O2 -pipe -g -feliminate-unused-debug-types -Wno-psabi -Wno-maybe-uninitialized -Wall -Wextra -pedantic -funsigned-char -std=gnu++17 -o CMakeFiles/adam_app.dir/src/main.cpp.o -c /home/ocp/src/cpp1/eden/src/adam/src/main.cpp" compile=$(echo ${CMD} | sed s#/opt/ocp/13.4.1/sysroots/x86_64-ocpsdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++#clang++#) compile=$(echo ${compile} | sed -e \ 's/-march=armv7ve/--target=armv7e-unknown-linux-elf/' \ -e 's/-o.*.cpp.o /-o test.o /' \ -e 's/-Wno-psabi//' \ -e 's/-Wno-maybe-uninitialized//') echo $compile
and running the command now results in
eval $compile In file included from /home/ocp/src/cpp1/eden/src/adam/src/main.cpp:3: . . . . /opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/boost/config/select_stdlib_config.hpp:18:12: fatal error: 'cstddef' file not found # include <cstddef> ^~~~~~~~~ 1 error generated.
Finally! no errors or warnings, but we still have an issue with the include files. So lets figure that one out.
Finding includes
as we saw in the previous section we are missing the system paths,
these needs to be the same as when we ran the
arm-poky-linux-gnueabi
. One way to find out which they are is to
compile with syntax-only
flag, which basically compiles without
output.
eval $CXX -v -std=c++17 -xc++ -fsyntax-only /dev/null
This outputs quite a bit of information but we are just interested in the system include paths, these can be figured out by checking between the lines
#include <...> search starts here: . . . . . End of search list.
So lets construct something that takes out these include directories.
Unfortunately the eval-command will print to stderr
which
is a bit of a hassle and we need to be able to extract the include
directories, and discard all the other output.
This might be a bit wild, but I will try to explain each of the rows
and try to explain what it does.
EPA=$( { eval $CXX -v -std=c++17 -xc++ -fsyntax-only /dev/null; } 2>&1 ) echo ${EPA} | \ sed -E -n -e '/<...>/,/End/p' | \ sed -E -e 's/^End.*$//' \ -e 's/^.*<...>.*$//' \ -e 's/^\s*//' \ -e '/^\s*$/d' | \ awk 'BEGIN{print "include_directories(SYSTEM"} \ {print " \"" $0 "\"" } \ END{print")"}'
- line 1
- This line will output both
stdin
andstderr
to the variable. The curly braces are used for output grouping, where the2>&1
indicates that both the stdin and stderr should be outputted to the variable. - line 3
- This little neat trick is Ranges by pattern it only includes the line between the two regexp. e.g
sed '/<regexp Begin>/,/<Regexp End>/p'
That means we are picking out the lines between <...>
and ^End
- line 4,5
Now piping the output from the previous range pattern we have to remove the End and the Begin (
<..>
) since those are included. One might do this with another range , e.g combining line number and range. .egecho $EPA | sed -n '/<...>/,/End/p' | sed -n '2,/^End/p' | sed '/^End/d'
- line 6
- Extending the sed expression, we now remove the white space from the beginning of every row.
- line 7
- And finally removes the lines without anything.
- line 8
- finally we create an awk expression that prints out the content as a cmake file.
The output of this expression would be:
include_directories(SYSTEM "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8" "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8" "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/backward" "/usr/include/clang/8.0.1/include" "/usr/local/include" "/usr/include/x86_64-linux-gnu" "/usr/include" )
If we redirect the output to a cmake file e.g clang-compile
, we can then include that file into our own project cmake file.
Building the first clang++
object.
If we now start to wrap things up , we can use both of the above methods to construct a command which hopefully build a complete object.
Lets start with creating a compile command (see Fix warnings).
CMD="/opt/ocp/13.4.1/sysroots/x86_64-ocpsdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -march=armv7ve -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi -DBOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION -DBOOST_ENABLE_ASSERT_HANDLER -I/home/ocp/src/cpp1/eden/include -I/home/ocp/src/cpp1/eden/src/adam/include -I/home/ocp/src/cpp1/eden/src/serpent/include -I/home/ocp/user_sysroots/13.4.1/usr/include -I/home/ocp/src/cpp1/eden/gen_files -I/home/ocp/src/cpp1/eden/src/adam/../include -O2 -pipe -g -feliminate-unused-debug-types -Wno-psabi -Wno-maybe-uninitialized -Wall -Wextra -pedantic -funsigned-char -std=gnu++17 -o CMakeFiles/adam_app.dir/src/main.cpp.o -c /home/ocp/src/cpp1/eden/src/adam/src/main.cpp" compile=$(echo ${CMD} | sed s#/opt/ocp/13.4.1/sysroots/x86_64-ocpsdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++#clang++#) compile=$(echo ${compile} | sed -e \ 's/-march=armv7ve/--target=armv7e-unknown-linux-elf/' \ -e 's/-o.*.cpp.o /-o test.o /' \ -e 's/-Wno-psabi//' \ -e 's/-Wno-maybe-uninitialized//') echo $compile
We need to include the paths for the $compile
command
EPA=$( { eval $CXX -v -std=c++17 -xc++ -fsyntax-only /dev/null; } 2>&1 ) includes=$(echo ${EPA} | \ sed -E -n -e '/<...>/,/End/p' | \ sed -E -e 's/^End.*$//' \ -e 's/^.*<...>.*$//' \ -e 's/^\s*//' \ -e '/^\s*$/d' | \ awk '{print " -isystem " $0}' | \ tr -d '\n')
I removed the cmake output from the awk expression and added
isystem
instead , and the last pipe will remove the new lines, since
otherwise each of the lines would be seen as a command in bash.
So the final output
CMD="/opt/ocp/13.4.1/sysroots/x86_64-ocpsdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -march=armv7ve -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi -DBOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION -DBOOST_ENABLE_ASSERT_HANDLER -I/home/ocp/src/cpp1/eden/include -I/home/ocp/src/cpp1/eden/src/adam/include -I/home/ocp/src/cpp1/eden/src/serpent/include -I/home/ocp/user_sysroots/13.4.1/usr/include -I/home/ocp/src/cpp1/eden/gen_files -I/home/ocp/src/cpp1/eden/src/adam/../include -O2 -pipe -g -feliminate-unused-debug-types -Wno-psabi -Wno-maybe-uninitialized -Wall -Wextra -pedantic -funsigned-char -std=gnu++17 -o CMakeFiles/adam_app.dir/src/main.cpp.o -c /home/ocp/src/cpp1/eden/src/adam/src/main.cpp" compile=$(echo ${CMD} | sed s#/opt/ocp/13.4.1/sysroots/x86_64-ocpsdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++#clang++#) compile=$(echo ${compile} | sed -e \ 's/-march=armv7ve/--target=armv7e-unknown-linux-elf/' \ -e 's/-o.*.cpp.o /-o test.o /' \ -e 's/-Wno-psabi//' \ -e 's/-Wno-maybe-uninitialized//') EPA=$( { eval $CXX -v -std=c++17 -xc++ -fsyntax-only /dev/null; } 2>&1 ) includes=$(echo ${EPA} | \ sed -E -n -e '/<...>/,/End/p' | \ sed -E -e 's/^End.*$//' \ -e 's/^.*<...>.*$//' \ -e 's/^\s*//' \ -e '/^\s*$/d' | \ awk '{print " -isystem " $0}' | \ tr -d '\n') echo $compile $includes eval $compile $includes
This will construct and create the object code using clang++.
Building a complete project
In the previous section we built an object using clang++, but what about building a complete project? This section, will show how to build the project. Even though each and every translation unit will be compiled into a object file, the complete project will end up failing due to that linking together the object files will fail.
Lets start with creating a the cmake file with the system includes that is needed, from the expression show here we just output the result to a file as the following expression shows. The output file is created in the project root directory
EPA=$( { eval $CXX -v -std=c++17 -xc++ -fsyntax-only /dev/null; } 2>&1 ) echo ${EPA} | \ sed -E -n -e '/<...>/,/End/p' | \ sed -E -e 's/^End.*$//' \ -e 's/^.*<...>.*$//' \ -e 's/^\s*//' \ -e '/^\s*$/d' | \ awk 'BEGIN{print "include_directories(SYSTEM"} \ {print " \"" $0 "\"" } \ END{print")"}' > clang_sys_includes.cmake
Next part is removing the flags which are not wanted , we did that in Fix Warning section. But since we are using cmake we need another way of removing the flags. We already identified the flags, all we need to do now is to remove those flags, and that can be done easily in the cmake and string replace.
cat >> clang_sys_includes.cmake <<EOF string(REPLACE "-Wno-psabi" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "-Wno-maybe-uninitialized" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") EOF
If we now include this file into our root CMakeLists.txt
e.g
cmake_minimum_required(VERSION 3.11) include(clang_sys_includes) . . .
If for some reason you set the CXX_FLAGS
somewhere in you cmake
files. Make sure that the include is added afterwards, otherwise it
might overwrite the changes we made.
The next part is to actually run the cmake from a build directory.
I just created a build_clang
directory and ran this command.
CXX="clang++ --target=armv7e-unknown-linux-elf \ -mthumb \ -mfpu=neon \ -mfloat-abi=hard \ -mcpu=cortex-a7" \ cmake ..
This will unfortunately not work. The reason is that cmake
will try
to build a small program to test the compiler, and since the linker is
not working properly it will fail. But there is a way of getting away
from this error, and that is to override the test.
CXX="clang++ --target=armv7e-unknown-linux-elf \ -mthumb \ -mfpu=neon \ -mfloat-abi=hard \ -mcpu=cortex-a7" \ cmake -DCMAKE_CXX_COMPILER_WORKS=1 -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ..
And finally we have got cmake to pass through the build.
We could not open compile_commands.json
and check the content.
[ { "directory": "/home/ocp/src/cpp1/eden/build_clang/src/adam", "command": "/usr/bin/clang++ --target=armv7e-unknown-linux-elf -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi -DBOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION -DBOOST_ENABLE_ASSERT_HANDLER -I/home/ocp/src/cpp1/eden/include -I/home/ocp/src/cpp1/eden/src/adam/include -I/home/ocp/src/cpp1/eden/src/serpent/include -I/home/ocp/user_sysroots/13.4.1/usr/include -I/home/ocp/src/cpp1/eden/gen_files -I/home/ocp/src/cpp1/eden/src/adam/../include -isystem /opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/c++/8.2.0 -isystem /opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/c++/8.2.0/arm-poky-linux-gnueabi -isystem /opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/c++/8.2.0/backward -isystem /opt/ocp/13.4.1/sysroots/x86_64-ocpsdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/include -isystem /opt/ocp/13.4.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/lib/gcc/arm-poky-linux-gnueabi/8.2.0/include -isystem /opt/ocp/13.4.1/sysroots/x86_64-ocpsdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/8.2.0/include-fixed -Wall -Wextra -pedantic -funsigned-char -std=gnu++17 -o CMakeFiles/adam_app.dir/src/main.cpp.o -c /home/ocp/src/cpp1/eden/src/adam/src/main.cpp", "file": "/home/ocp/src/cpp1/eden/src/adam/src/main.cpp" }, . . . ]
Finally we have a compile_command.json
which the clang tools
understands. We can notice that the flags are removed and that the
isystem is include.
Now what happens if we actually run the build command on
it?
/usr/bin/ld: unrecognised emulation mode: armelf_linux_eabi Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu i386linux elf_l1om elf_k1om i386pep i386pe clang: error: linker command failed with exit code 1 (use -v to see invocation) . . .
That was kind of expected, its able to build the object files. But the linker fails.