Std::string to String in release builds

Hi,

First, great job with the interop - I develop apps on iOs and Android and use c++ for a lot of common code, so I nearly fell off my chair when I saw the progress on this.

I've created a new app to try it out, and so far it is working really well, except I've just hit a problem when I try to build/run my app in release rather than debug.

I'm using XCode15, using a modulemap for my c++ lib, inerop enabled for the target (release and debug). Building and running in debug works great. When I switch to release, I get swift compile errors doing the equivalent of this:

var cppStr = std.string()
// ...Some code to populate the cppStr
var swiftStr = String(cppStr)

The swift compiler errors start with:

no exact matches in call to initializer

note: found candidate with type '(std.string) -> String' (aka '(std.__1.basic_string<CChar, char_traits, allocator>) -> String')

Looking at the compiler call, I can see -cxx-interoperability-mode\=default being passed as a parameters (same as in debug builds), which seems like it should work fine.

It is like the compiler is not finding the String extension in CxxStdlib, but I have no idea how to fix it. Does anyone have any ideas?

Earlier this year we've fixed a Swift compiler bug that was causing this kind of errors. Could you please try using the latest Xcode 16 to see if that fixes the issue for you?

1 Like

Hi,

Thanks for the reply. I did try previously with a beta Xcode 16 and had the same issue, however I have just tried it again and I can confirm that it actually works with Xcode 16 (so either I made a mistake when I originally checked on Xcode 16, or I've cleared some kind of cache).

Using Xcode 16 Version 16.0 beta 6 (16A5230g) I'm able to build and run release builds for testing (and build for Archive for upload to the store, which is what I was originally trying to do)

Thanks!

2 Likes