# \[RESOLVED\] C++ compiler use not correct language standard

**URL:** <https://forums.swift.org/t/resolved-c-compiler-use-not-correct-language-standard/58755>\
**Category:** C++ interoperability\
**Tags:** packagemanager, cxx, cxx-interop, swift-package\
**Created:** [July 7, 2022, 11:49am UTC](https://forums.swift.org/t/resolved-c-compiler-use-not-correct-language-standard/58755 "2022-07-07T11:49:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SpectralDragon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/spectraldragon/32/5035_2.png) [@SpectralDragon](https://forums.swift.org/u/SpectralDragon)\
**Post date:** [July 7, 2022, 11:49am UTC](https://forums.swift.org/t/resolved-c-compiler-use-not-correct-language-standard/58755/1 "2022-07-07T11:49:36Z")

</div>

# A problem

I'm trying to wrap c++ lib [box2d](https://github.com/erincatto/box2d) in SPM package, but when I try to build a target, then I receive a lot of errors, like this:

 ![image](https://global.discourse-cdn.com/swift/original/3X/0/5/052ff8983c43f68ff2ac93974af05daf72eaab86.png)

and this

 ![image](https://global.discourse-cdn.com/swift/original/3X/7/a/7a9a52a6220fbe109aa7a620b1bc50a3d08d8f42.jpeg)

As you can see, the main problem is C99 standard, because some syntax features like constructor with default values or bool types not supported in C99. I explicitly set `cxxLanguageStandard` to .cxx11, but it doesn't works for me. I've no idea what I'm doing wrong, but looks like this is a problem of compiler.

The package you can see here: [GitHub - AdaEngine/box2d-swift: The box2d bridging to Swift](https://github.com/SpectralDragon/box2d-swift)

# How to reproduce

1. Download sources from repo
2. Run target 'box2d-test'

---

<div class="post-metadata">

**Author:** ![egor.zhdan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/egor.zhdan/32/44150_2.png) [@egor.zhdan](https://forums.swift.org/u/egor.zhdan)\
**Post date:** [July 7, 2022, 11:59am UTC](https://forums.swift.org/t/resolved-c-compiler-use-not-correct-language-standard/58755/2 "2022-07-07T11:59:31Z")

</div>

C++ interoperability is currently disabled by default in Swift. Swift tries to import the headers as if they were Objective-C headers, and the syntax that you use is not valid in Objective-C. To actually enable C++ interoperability, you'll need to pass a compiler flag: `-Xfrontend -enable-experimental-cxx-interop`. You could do that with SwiftPM's unsafe flags mechanism:  
`unsafeFlags(["-Xfrontend", "-enable-experimental-cxx-interop"])`.

---

<div class="post-metadata">

**Author:** ![SpectralDragon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/spectraldragon/32/5035_2.png) [@SpectralDragon](https://forums.swift.org/u/SpectralDragon)\
**Post date:** [July 7, 2022, 12:13pm UTC](https://forums.swift.org/t/resolved-c-compiler-use-not-correct-language-standard/58755/3 "2022-07-07T12:13:01Z")

</div>

> [@egor.zhdan](#):
>
> enable-experimental-cxx-interop

If I understand correctly, I should pass flags to `swiftSettings`, but what minimal version of Swift I should have? Current version is 5.6

 ![image](https://global.discourse-cdn.com/swift/original/3X/a/e/aed898a95039e72ba6ef1706ac831134450ff6da.png)

---

<div class="post-metadata">

**Author:** ![egor.zhdan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/egor.zhdan/32/44150_2.png) [@egor.zhdan](https://forums.swift.org/u/egor.zhdan)\
**Post date:** [July 7, 2022, 12:35pm UTC](https://forums.swift.org/t/resolved-c-compiler-use-not-correct-language-standard/58755/4 "2022-07-07T12:35:06Z")

</div>

> I should pass flags to `swiftSettings`

Yes, that is correct.

I would recommend using a nightly Swift toolchain when experimenting with C++ interop. The project is moving quickly, and you'll likely find issues in release toolchains that are already fixed in trunk.  
That said, for Swift 5.6 the correct flag is `enable-cxx-interop`.

---

<div class="post-metadata">

**Author:** ![SpectralDragon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/spectraldragon/32/5035_2.png) [@SpectralDragon](https://forums.swift.org/u/SpectralDragon)\
**Post date:** [July 7, 2022, 12:38pm UTC](https://forums.swift.org/t/resolved-c-compiler-use-not-correct-language-standard/58755/5 "2022-07-07T12:38:06Z")

</div>

> [@egor.zhdan](#):
>
> enable-cxx-interop

`enable-cxx-interop` is works! Thanks a lot!
