[llvm-dev] Cross compiling C++ program

Jonathan Roelofs via llvm-dev llvm-dev at lists.llvm.org
Wed Aug 2 16:48:20 PDT 2017



On 8/2/17 5:28 PM, Goran Mekić via llvm-dev wrote:
> Hello,
> 
> As a newcomer to the libcxx implementation, I'll probably ask a silly question, but why following example can be compiled natively, but not cross compiled?
> 
> #include <cstdlib>
> using ::atof;
> int main() {
>    return 0;
> }
> 
> Native compile: clang++ -o example example.cpp
> Cross compile: clang++ -fno-builtin -fno-exceptions -fcheck-new -nostdlib -ffreestanding -target arm-none-eabi -march=armv7-m -mcpu=cortex-m4 -Wall -Wshadow -Wundef -g -Os -fno-strict-aliasing -fomit-frame-pointer -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -stdlib=libc++ -o example example.cpp
> 
> Error I get:
> In file included from example.cpp:1:
> In file included from /usr/include/c++/v1/cstdlib:85:

I strongly recommend against using the host's headers when cross 
compiling. You need to either find or build an arm-none-eabi sysroot, 
and use the --sysroot= flag.


Jon

> /usr/include/c++/v1/__config:938:4: error: "No thread API"
> #  error "No thread API"
>     ^
> 1 error generated.
> 
> 
> Without -stdlib=libc++ I get this error:
> example.cpp:1:10: fatal error: 'cstdlib' file not found
> #include <cstdlib>
>           ^~~~~~~~~
> 1 error generated.
> 
> My OS is FreeBSD 11.1 and Clang version is 4.0.0. What am I not understanding well enough and could you recommend reading something on the topic? Any help is welcome! Thank you!
> 
> Regards,
> meka
> 
> 
> 
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> 

-- 
Jon Roelofs
jonathan at codesourcery.com
CodeSourcery / Mentor Embedded / Siemens


More information about the llvm-dev mailing list