Here is my feedback to Apple and their reply:
Basic information
Please provide a descriptive title for your feedback:
undefined symbols of shrink_to_fit() when compiling Cronet on iOS 15 with Xcode 13
Which area are you seeing an issue with?
Xcode
What type of feedback are you reporting?
Incorrect/unexpected behavior
Details
What version of Xcode are you using?
13.1
Description
Please describe the issue:
When compiling Cronet on the iOS platform with Xcode 13.1 and iOS 15.0, an error happens:
Undefined symbols for architecture arm64:
"std::__1::basic_string<unsigned short, base::string16_internals::string16_char_traits, std::__1::allocator >::shrink_to_fit()", referenced from: base::UTF8ToUTF16(char const*, unsigned long, std::__1::basic_string<unsigned short, base::string16_internals::string16_char_traits, std::__1::allocator >) in libbase.a(utf_string_conversions.o) base::WideToUTF16(wchar_t const, unsigned long, std::__1::basic_string<unsigned short, base::string16_internals::string16_char_traits, std::__1::allocator >*) in libbase.a(utf_string_conversions.o)
ld: symbol(s) not found for architecture arm64
subprocess.CalledProcessError: Command '['clang++', '-B', '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/', '-shared', '-Xlinker', '-install_name', '-Xlinker', '@rpath/Cronet.framework/Cronet', '-Xlinker', '-objc_abi_version', '-Xlinker', '2', '-arch', 'arm64', '-Werror', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.0.sdk', '-stdlib=libc++', '-miphoneos-version-min=8.0', '-fembed-bitcode', '-Wl,-ObjC', '-o', 'obj/components/cronet/ios/arm64/Cronet', '-Wl,-filelist,obj/components/cronet/ios/arm64/Cronet.rsp', '-framework', 'UIKit', '-framework', 'CoreFoundation', '-framework', 'CoreGraphics', '-framework', 'CoreText', '-framework', 'Foundation', '-framework', 'JavaScriptCore', '-framework', 'CFNetwork', '-framework', 'MobileCoreServices', '-framework', 'Security', '-framework', 'SystemConfiguration', '-lresolv']' returned non-zero exit status 1
Please list the steps you took to reproduce the issue
- checkout Chromium source code
- set up Cronet build environment
- compile with Xcode 13.1 and iOS 15.0, macOS v12.0.1 (Sierra)
What did you expect to happen?
Compile successfully like Xcode 12 does
What actually happened?
Undefined symbols for architecture arm64: "std::__1::basic_string<unsigned short, base::string16_internals::string16_char_traits, std::__1::allocator >::shrink_to_fit()", referenced from: base::UTF8ToUTF16(char const*, unsigned long, std::__1::basic_string<unsigned short, base::string16_internals::string16_char_traits, std::__1::allocator >) in libbase.a(utf_string_conversions.o) base::WideToUTF16(wchar_t const, unsigned long, std::__1::basic_string<unsigned short, base::string16_internals::string16_char_traits, std::__1::allocator >*) in libbase.a(utf_string_conversions.o)
Apple's reply:
It looks like you are using std::basic_string<char16, base::string16_char_traits>, which comes from Chromium. Since there is an explicit instantiation declaration for that type 2, the instantiation of std::basic_string<char16, base::string16_char_traits> appears to be provided in a library that probably ships with Chromium. You need to make sure you link against it, otherwise such link errors are to be expected.
We think this link may also be relevant: https://stackoverflow.com/a/17484003/627587. It doesn't pertain to libc++, however the issue is most likely the same.
Also, in case you are wondering why this started happening with Xcode 13.1, we suspect this is simply because std::basic_string<char16, base::string16_char_traits>::shrink_to_fit was previously being inlined in your code, which means that the fact that you're not linking to the required Chromium library was not triggering any error. We made some changes to shrink_to_fit and the compiler is probably deciding not to inline it anymore because it is more efficient to use the instantiation announced by the string16.h header, which uncovers the fact that you haven't been linking against that library.