Compiling C++ source for iOS - missing std::to_string

I am compiling our multiplatform c++ code for inclusion in apps on iOS.

When I run the build (through cmake with an appropriate ios toolchain), an error is reported saying it cannot find std::to_string

I have iOS sdk 14,2 installed with XCode 12.2

As this is a standard part of C++11 and my compile options indicate that I need this : -std=c++11 -stdlib=libc++, I expected no problems.

Is this missing from the apple c++11 implementation ?

Is there something I have missed ?

As a first sanity check, it’s not missing. In a quick test here on Xcode 14.5.1, I am able to call std::to_string() in an Objective-C++ (.mm) file here. You do need to add #import <string> at the top of the file.

You mentioned using CMake rather than building directly in Xcode, so maybe that's the difference. Can you validate the SDK support by making a minimal test app in Xcode that can access std::to_string() successfully?

Assuming that works (so it builds via Xcode but not CMake) then I'd see if the CMake build environment may be including some standard headers (<string> in this case) that aren't included automatically in an Xcode build.

Hi Scott,

Thanks for your reply.

I have tried both creating a C++ file and an Objective-C++ file as you proposed.

In both of these, XCode complains that it cannot find the class stringor even the header (obj-c++) <string>.

Just for to remind you, I am having to use XCode 12.2 and not 14.5 due to system constraints.

Any ideas ?

To answer my own question - Yes, I was missing something ! :-(

One of those stupid bugs that you go over being persuaded that there is nothing wrong.

I was trying to do a to_string on a pointer to an int without dereferencing it - as I said, stupid.

Sorry for the bother.

Compiling C++ source for iOS - missing std::to_string
 
 
Q