質問

There are some C++ files in my Objective-C project. In order to use STL in header files, I set the project setting to compile source as Objective-C++ in "Build Setting".

But now, I want to use RegexKitLite in my project. I found out RegexKitLite give a compilation error in the Objective-C++ mode,but does compile correctly in the Objective-C mode or when determined automatically in "According to File Type" mode.

My questions is:

  1. How to set a single header file to compile as C++? (I set the File Type as "C++ Header" in Identity and Type, but no effect is seen.).

  2. How to use RegexKitLite from "Objective-C++"?

役に立ちましたか?

解決

Header files are not a compilation unit (they are not compiled by themselves, but just included in other files), so setting the type does not have any influence on compilation.

If you include the header from some C++-compiled file, it will be compiled with C++ compiler. Similarly, if you include the exactly the same header file from Objective-C file, it will be compiled with Objective-C compiler.

他のヒント

Headers are not specific by defaut. .cpp use cpp compiler and .mm obj c. So if you have an error it may be because you use a c++ that can not be compiled in objective c (but I don t think it is possible) Better guess you use a header including obj c declarations in a C++ header.

separate your code to only include c++ compliant code in the cpp files

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top