0

I have a C++11 header and source file to call from swift (of course i'm including the header in the bridging header). I've set the build settings for C++ to:

"C++ Language Dialect" -> "C++11 [-std=c++11]"

"C++ Standard Library" -> "libc++ (LLVM standard C++ library with C++11 support)"

It still can't find some #include (file not found):

#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include <utility>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <utility>
vale
  • 1,376
  • 11
  • 25
  • You cannot call C++ functions directly from Swift, compare http://stackoverflow.com/questions/24042774/can-i-mix-swift-with-c-like-the-objective-c-mm-files. – Martin R Dec 12 '15 at 13:28
  • Although Swift isn't designed to work with C++ yet, there are people who are able to do it by creating a wrapper in Objective-C. Here's a video example: https://www.youtube.com/watch?v=0x6JbiphNS4 – Dan Beaulieu Dec 12 '15 at 13:53
  • Oh thanks, will do. No idea why I missed that. – vale Dec 12 '15 at 17:21

1 Answers1

0

As mentioned in one of the comments, you can use a wrapper. In fact, the wrapper doesn't even have to be in Objective-C. It can actually be a C++ wrapper, but the functions intended to be called from Swift should have C linkage. See http://www.swiftprogrammer.info/swift_call_cpp.html for a tutorial.

Anatoli P
  • 4,791
  • 1
  • 18
  • 22