[llvm-dev] Cross compiling C++ program
Jonathan Roelofs via llvm-dev
llvm-dev at lists.llvm.org
Fri Aug 4 15:40:44 PDT 2017
On 8/4/17 4:29 PM, Goran Mekić wrote:
> On Fri, Aug 04, 2017 at 04:03:35PM -0600, Jonathan Roelofs wrote:
>>>> 1) Pick a directory as your sysroot
>>> ~/arm-sysroot
>>>
>>>> 2) Install the libc headers there (without having built it)
>>> What I did was mv musl-*/include ~/arm-sysroot/usr/include.
>> I think you need to copy them, not move them.
> On a new directories and fresh untar of musl, I don't think there's a difference
I was assuming you'd want to build it from the same sources later...
>
>
>>>> 3) Build clang w/ baremetal cache, pointing it at the partially built
>>>> sysroot.
>>> cmake -G 'Unix Makefiles' -DBAREMETAL_ARMV7EM_SYSROOT=~/arm-sysroot -C ../../code/clang/cmake/caches/BaremetalARM.cmake ../../code/clang
>> Sorry, I wasn't explicit enough. You need to define all of the variables
>> that the cache is looking for.
>>
>>> loading initial cache file ../../code/clang/cmake/caches/BaremetalARM.cmake
>>> -- Found LLVM_CONFIG as /usr/local/bin/llvm-config
>>> -- Building with -fPIC
>>> -- Could NOT find Z3 (missing: Z3_LIBRARIES Z3_INCLUDE_DIR) (Required is at least version "4.5")
>>> -- Clang version: 4.0.1
>>> CMake Error at /usr/local/llvm40/lib/cmake/llvm/LLVM-Config.cmake:203 (message):
>>> Library `BinaryFormat' not found in list of llvm libraries.
>>> Call Stack (most recent call first):
>>> /usr/local/llvm40/lib/cmake/llvm/AddLLVM.cmake:508 (llvm_map_components_to_libnames)
>>> cmake/modules/AddClang.cmake:86 (llvm_add_library)
>>> lib/AST/CMakeLists.txt:6 (add_clang_library)
>>>
>>> -- Configuring incomplete, errors occurred!
>>> See also "/usr/home/meka/repos/clang/build/clang/CMakeFiles/CMakeOutput.log".
>> I think it found an installed llvm, and is trying to use that to build clang
>> against. First, the clang and llvm's versions have to match. Second, when I
>> mentioned building clang, I really meant building llvm+clang... sorry.
>>
>> $ cmake -G 'Unix Makefiles' -DBAREMETAL_ARMV7EM_SYSROOT=~/arm-sysroot -C
>> path/to/copy/of/edited/BaremetalARM.cmake path/to/llvm
>>
>> Where your path/to/llvm has the symlinks:
>>
>> * path/to/llvm/tools/clang -> path/to/clang
> ln -s `which clang40` path/to/llvm/tools/clang
No, not the binary, the source.
The closer to top of trunk you pull the source, the easier it'll be to
get it working. A lot of the upstreaming of baremetal support has been
*very* recent.... "bleeding edge" recent.
>> * path/to/llvm/runtimes/compiler_rt path/to/compiler_rt
> ln -s path/to/llvm/projects/compiler-rt path/to/llvm/runtimes/compiler_rt
>
> Is that right?
Sorry, it should be spelled `compiler-rt`, not `compiler_rt`.
>> And by "edited BaremetalARM.cmake" I mean you can strip out the other
>> targets in there that you don't need.
> So I have copied BaremetalARM.cmake into llvm/cmake/caches/BaremetalARM.cmake to be able to alter it, I've put all other repos in llvm/projects and the command is:
Leave all the others out for now. An in-tree build of them is just going
to give you host binaries, which isn't helpful in your case. You'll have
to build them "out of tree".
Might be a helpful exercise for you to try building vanilla clang with
runtimes for the host, before worrying about how to build everything for
your baremetal case:
http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summary
>
> # cmake -G 'Unix Makefiles' -DBAREMETAL_ARMV7EM_SYSROOT=~/arm-sysroot -DBAREMETAL_ARMV6M_SYSROOT=~/arm-sysroot -DBAREMETAL_ARMV7M_SYSROOT=~/arm-sysroot -C ../../code/llvm/cmake/caches/BaremetalARM.cmake ../../code/llvm
>
> Before adding all repos into llvm/projects, it complained about 'Specified distribution component 'clang' doesn't have a target' (just an example). Now I have 'Specified distribution component 'builtins-armv6m-none-eabi' doesn't have a target' as error.
I think that error happened because you symlinked the clang binary in,
not the source.
Jon
--
Jon Roelofs
jonathan at codesourcery.com
CodeSourcery / Mentor Embedded / Siemens
More information about the llvm-dev
mailing list