Undefined Symbol when using C++ interop and URL.bookmark()

thanks for the great work of adding C++ interoperability to Swift.

I've update a project, that uses a custom C++ Library inside a Swift package.

All works fine unless I add code that uses URL.bookmarkData() to the main app project.

This leads to the following Error:

Undefined symbol: _$s10Foundation3URLV12bookmarkData7options30includingResourceValuesForKeys10relativeToAA0D0VSo5NSURLC23BookmarkCreationOptionsV_ShySo16NSURLResourceKeyaGSgACSgtKF

I've created a small sample project here.
When I remove this line, everything builds fine.

Am I doing something wrong, or is this a bug in Xcode / C++ interoperability?


I’ve gotten a linker error from Xcode before when it couldn’t find an extension method. I can’t remember exactly how I fixed it but it was probably some combination of {clean build, restart Xcode, delete DerivedData}.

Personally, I don’t think Swift should ever give you a linker error, unless a C/C++ header declares a function that isn’t actually implemented. So, I would consider this a bug if none of my above suggestions fix it. That being said, I also haven’t been following C++ interop too closely.

Thanks for the feedback! That's definitely a bug.
I filed a GitHub issue for us to track it here: [cxx-interop] Enabling C++ interop leads to linking errors with URL.bookmark() · Issue #66501 · apple/swift · GitHub


We're seen some similar link errors with functions that take default parameters.

As Puyan says we have seen this one in some cases, but it is great to have a repro and know it is still there, because we could not reduce our problem, and it suddently went away with newer 5.9 improvements. In our case it was happening in our own function and the solution was providing the default parameters in every invocation place. Try to see if it goes away doing try? url.bookmarkData(options: [], includingResourceValuesForKeys: nil, relativeTo: nil).

1 Like

Unfortunately that doesn't solve the issue. Still there, even if I fill in all default parameters.

I noticed another example of this issue using Data(contentsOf:).

let data = try? Data(contentsOf: url)

Undefined symbol:

are you interested in any more reports of this kind of thing?

Hi @pwallrich

I have been debugging your issue using your GH/pwallrich/swiftcxx-interop-bug repo + Xcode project at

I believe your issue is already fixed by [cxx-interop] Add fix for corner case where NS_OPTIONS typedef has to be desugared by plotfi · Pull Request #66619 · apple/swift · GitHub.

Have you tried the most recent Xcode beta?

1 Like

Sorry for the very late reply. Tough summer :see_no_evil:

Just tested it with 15.0.1 and it works :slight_smile: