I am trying to interop with basic C++ method in Swift. But Xcode gives me an error when I build the project;
'string' file not found
I have researched this issue on StackOverflow but every solution and answers didn't solve my problem. And I started to think that what if I use libstdc++ rather than libc++. Then I found that libstdc++ was removed with Xcode 10. I found the files on Github and apply it to appropriate file directories. And that did not do much either. Did you guys encounter with this kind of problem before?
This is my header file.
#ifndef CPPTest_hpp
#define CPPTest_hpp
#include <string>
std::string saySomething();
#ifdef __cplusplus
extern "C" {
#endif
int returnNumber();
#ifdef __cplusplus
}
#endif
#endif CPPTest_hpp
This is the cpp file.
#include "CPPTest.hpp"
std::string saySomething()
{
return "Welcome to C++";
}
int returnNumber()
{
return 10;
}
This is where I expose header to Swift
#include "CPPTest.hpp"
After all, When I build the project. It gives me an error like;
'string' file not found
Why does this error occur?
By the way, it works when I use integer as return type and its appropriate implementation in cpp file.
If you stumble upon this question, my problem was that the
MODULE_VERIFIER_SUPPORTED_LANGUAGES
Build Setting included objective-c and objective-c++. Obviously, in objective-c there is no <string> header from c++.
Either use the #ifdef __cplusplus macro or change above Xcode Build Setting to only include c++ and/or objective-c++.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With