libcxx: cstdio / stdio.h - missing file

Hi, guys!

I try to use libcxx headers with clang via C API (libclang to be more detailed) and i’ve found that cstdio file (http://llvm.org/svn/llvm-project/libcxx/tags/RELEASE_34/final/include/cstdio) includes stdio (line 100) which is missing. I can’t find it in “include” and subdirectories.

Am i missing smth?

Regards, Anton.

Check the recent posts by Larry Evans.

What's the output of:

clang++ helloworld.cpp -v

What is your platform?

Ben

I’m going to use it on ios.

Mac os x output:

MBA-Anton:llvm_34_ios_armv7_build_noenv asmirnov$ clang++ helloworld.cpp -v

Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)

Target: x86_64-apple-darwin13.3.0

Thread model: posix

clang: error: no such file or directory: ‘helloworld.cpp’

Apologies for not being particularly explicit in my description

What's the output of:

echo "int main() {}" > helloworld.cpp && clang++ helloworld.cpp -v

Ben

BTW. i’m cross-compiling clang 3.4 for ios and libcxx release_30

To be more detaild i don’t have any problems on my dev machine (Mac OS X with XCode toolchain).

I’d like to use libcxx with clang on ios device.

Anyway : output on my dev machine

MBA-Anton:llvm_34_ios_armv7_build_noenv asmirnov$ echo “int main() {}” > helloworld.cpp && clang++ helloworld.cpp -v

Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)

Target: x86_64-apple-darwin13.3.0

Thread model: posix

“/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang” -cc1 -triple x86_64-apple-macosx10.9.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name helloworld.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 236.3 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/lib/clang/5.1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/asmirnov/Documents/dev/src/llvm_34_ios_armv7_build_noenv -ferror-limit 19 -fmessage-length 100 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/64/fwfkm1k51zbd4_c5lwpsbljh0000gn/T/helloworld-7e1d2f.o -x c++ helloworld.cpp

clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin13.3.0

ignoring nonexistent directory “/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/v1”

ignoring nonexistent directory “/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/local/include”

ignoring nonexistent directory “/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/Library/Frameworks”

#include “…” search starts here:

#include <…> search starts here:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/lib/c++/v1

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/lib/clang/5.1/include

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks (framework directory)

End of search list.

“/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld” -demangle -dynamic -arch x86_64 -macosx_version_min 10.9.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -o a.out /var/folders/64/fwfkm1k51zbd4_c5lwpsbljh0000gn/T/helloworld-7e1d2f.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/lib/clang/5.1/lib/darwin/libclang_rt.osx.a

MBA-Anton:llvm_34_ios_armv7_build_noenv asmirnov$

Then you'll also need to invoke clang with the magic incantation for cross-compiling to that device in order to ascertain why it can't find the c headers. I don't remember the command off the top off my head.

By specifying -v along with the suitable build parameters for cross-compiling, and by inspecting the header search path n the output, you should be able to determine what's going wrong. More than likely, you are not specifying a valid platform or isysroot, or isystem or whatever.

This is actually not the right place for support on Apple LLVM, but I suspect that with -v and a little thought, you will figure it out.

Ben

Ben.

I should be clear from the beginning.

I already did cross-compiled Clang for ios and my question is not related to Apple LLVM completely.
It’s about libcxx.

The problem is that libcxx header file cstdio includes file stdio.h which is absent.
Should it be in system headers?

At this time i do have working libclang in ios app and i’d like to add libcxx to it thouh i’m not sure if clang already includes libc++.
When i copy libcxx headers and add -I to libclang command-line while parsing files i have stdio.h file absent deagnostics.

i’m trying to understand he reason.

What happen with:

echo "int main() {}" > helloworld.cpp && gcc helloworld.cpp -v

? That should show where gcc believes stdio.h is located.

HTH.

-regards,
Larry

Mea culpa, I obviously meant clang.

Ben

Ben.

I should be clear from the beginning.

I already did cross-compiled Clang for ios and my question is not
related to Apple LLVM completely.
It's about libcxx.

It's about how the Clang from Apple LLVM finds headers.

The problem is that libcxx header file cstdio includes file stdio.h
which is absent.
Should it be in system headers?

See below.

At this time i do have working libclang in ios app and i'd like to add
libcxx to it thouh i'm not sure if clang already includes libc++.
When i copy libcxx headers and add -I to libclang command-line while
parsing files i have stdio.h file absent deagnostics.

I'm not sure how you are specifying your command line.

i'm trying to understand he reason.

The correct path is not included.

Something like the following, but you may have to apply common sense if the paths are different on your system.

echo "int main() {}" > helloworld.cpp && clang++ -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk helloworld.cpp -v

I tested it this time, rather than randomly typing whilst half-asleep.

Looks like stdio.h will be picked up from:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/usr/include/

Ben

Thanks a lot, guys.

Now it’s clear to me how it works - AFAIK it requires stdio.h header that should be found in system headers
as it’s not included in libcxx include paths. Please correct my if i’m wrong

As i said it works ok for my dev machine and stdio.h is found on it correctly.
I’m trying to make it working on ios (unrooted) where there are a lot of restrictions as you know.
So now i’m going to add stdio.h and probably some other headers to ios app bundle and add -I for .cpp command-line to process by libclang.

BTW as ios does not allow fork i can’t just check the same to find stdio.h on ios device but it’s obvious it can’t be found at this time.

Thanks and regards, Anton.

Thanks a lot, guys.

Now it's clear to me how it works - AFAIK it requires stdio.h header
that should be found in system headers
as it's not included in libcxx include paths. Please correct my if i'm wrong

Yes, stdio.h is part of libc not libcxx and should exist in the sysroot *for the platform you're compiling for*.

As i said it works ok for my dev machine and stdio.h is found on it
correctly.

It's likely that the compiler is configured to compile for your dev machine by default.

I'm trying to make it working on ios (unrooted) where there are a lot of
restrictions as you know.

I don't know what those restrictions are, but you should probably tell your compiler where it should find the sysroot for the platform you wish to compile for.

So now i'm going to add stdio.h and probably some other headers to ios
app bundle and add -I for .cpp command-line to process by libclang.

That's probably not a great idea, the libc for your dev machine and the one on your ios device might differ.

BTW as ios does not allow `fork` i can't just check the same to find
stdio.h on ios device but it's obvious it can't be found at this time.

I'm lost.

Thanks and regards, Anton.

Good luck.

Ben

Thanks a lot, guys.

Now it's clear to me how it works - AFAIK it requires stdio.h header
that should be found in system headers
as it's not included in libcxx include paths. Please correct my if i'm
wrong

Yes, stdio.h is part of libc not libcxx and should exist in the sysroot
*for the platform you're compiling for*.

As i said it works ok for my dev machine and stdio.h is found on it

correctly.

It's likely that the compiler is configured to compile for your dev
machine by default.

I'm trying to make it working on ios (unrooted) where there are a lot of

restrictions as you know.

I don't know what those restrictions are, but you should probably tell
your compiler where it should find the sysroot for the platform you wish to
compile for.

I can see sysroot folder for XCode toolchain.

So now i'm going to add stdio.h and probably some other headers to ios

app bundle and add -I for .cpp command-line to process by libclang.

That's probably not a great idea, the libc for your dev machine and the
one on your ios device might differ.

I'm going to copy headers from XCode toolchain (sysroot) so i expect it to
be exactly (or 100% compatible) the same as on device.

BTW as ios does not allow `fork` i can't just check the same to find

stdio.h on ios device but it's obvious it can't be found at this time.

I'm lost.

It means i can just launch "echo > .. gcc .. -v" on unrooted device and
check out the output.

Thanks and regards, Anton.

Good luck.

Thanks

Wow, ok, sorry, you did say it, and I did read it, but I didn't process it; you want to run the clang compiler on the ios device. My apologies for talking cross-purposes with you.

Then I suggest you copy the sysroot for that platform to the device somewhere, if that has to be in the app bundle, so be it.

Ben

Oh, that mistyping. i’m really sorry for it.
"… i can’t just launch … on unrooted ios device "

Otherwise i did it from the beginning.

Yes, i’m trying to make clang working on ios.
Everything seems to be okay for now, but i have to use static linking instead on running executables.

At this point i’m having working libclang which performs lexing, parsing and tokenizing and performing diagnostics.
But i’m fixing that missing stdio.h file diagnosics message.

Thanks,
Anton