#include file not found in iOS in C++ file

后端 未结 2 581
生来不讨喜
生来不讨喜 2021-02-04 11:18

I have a objective c/c++ project under iOS, moving it from OS/X and I get a \'file not found\' error on

#include 

It\'s a clean p

相关标签:
2条回答
  • 2021-02-04 11:46

    If you include a header in an ObjC file and it includes <string> then you hit errors like this. For all .m files XCode uses a C compiler (clang or llvm-gcc). For all .mm files it will use (clang++ or llvm-g++).

    I suggest going through and renaming all your .m files to .mm. Including main.m to main.mm.

    0 讨论(0)
  • 2021-02-04 11:50

    Are you really sure <string> is included only from a .cpp file?

    I just tested on a fresh project, by adding a .cpp file and including <string>, and it works, just as expected (same Xcode version, same SDK version).

    But if I include <string> in a .m file, then of course I got a «file not found» compiler error.

    So double-check this, as the error may come from here.

    Do you include <string> from a .cpp file only, or from a .h file, intended to be used by a .cpp implementation?
    Then maybe it's also included by a .m file, hence the error.

    Also check your precompiled headers, if any, to see if you include some C++ stuff there...

    Also remember, in that later case, that you can rely on the __cplusplus macro, when needed.

    0 讨论(0)
提交回复
热议问题