代码之家  ›  专栏  ›  技术社区  ›  Yekta Sarıoğlu

为什么xcode给出的错误'string'文件找不到?

  •  0
  • Yekta Sarıoğlu  · 技术社区  · 6 年前

    我尝试用基本的C++方法在SWIFT中进行互操作。但是xcode在我构建项目时给了我一个错误;

    'string' file not found
    

    我在stackoverflow上研究过这个问题,但是每一个解决方案和答案都不能解决我的问题。我开始想如果我使用libstdc++而不是libc++。然后我发现libstdc++是用xcode 10删除的。我在github上找到了这些文件,并将其应用到适当的文件目录中。这也没什么用。你们以前遇到过这种问题吗?

    这是我的头文件。

    #ifndef CPPTest_hpp
    #define CPPTest_hpp
    
    #include <string>
    
    std::string saySomething();
    
    #ifdef __cplusplus
    extern "C" {
    #endif
        int returnNumber();
    
    #ifdef __cplusplus
    }
    #endif
    
    
    #endif CPPTest_hpp
    

    这是cpp文件。

    #include "CPPTest.hpp"
    
    std::string saySomething()
    {
        return "Welcome to C++";
    }
    
    int returnNumber()
    {
        return 10;
    }
    

    在这里我向斯威夫特揭发头球

    #include "CPPTest.hpp"
    

    毕竟,当我建立这个项目的时候。它给了我一个错误;

    找不到“string”文件

    为什么会发生这个错误?

    顺便说一下,当我在cpp文件中使用integer作为返回类型及其适当的实现时,它可以工作。

    0 回复  |  直到 6 年前