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: /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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170803/af89c86c/attachment.sig>
Jonathan Roelofs via llvm-dev
2017-Aug-02 23:48 UTC
[llvm-dev] Cross compiling C++ program
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
On Wed, Aug 02, 2017 at 05:48:20PM -0600, Jonathan Roelofs wrote:> 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. > > > JonOK, that's a start. I found https://www.llvm.org/docs/HowToCrossCompileLLVM.html. Is it enough for --sysroot? In case it is, what should be the value of -DLLVM_DEFAULT_TARGET_TRIPLE if I want to use FreeBSD as host and Cortex-M4 as sysroot? Thanx! Regards, meka -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170803/28cb64bc/attachment.sig>