AVEbrahimi
AVEbrahimi

Reputation: 19204

using C++ code in XCode

I tried to import a C++ library into XCode, I renamed the .cpp to .mm but when I try to compile it shows me errors like this:

DateOps.h:23: error: expected '=', ',', ';', 'asm' or '_attribute_' before 'DateOps'

start of DateOps.h file

#if !defined( DATE_OPS__H )
#define DATE_OPS__H

typedef int MonthDays[13];

typedef long YearEndDays[2];

class DateOps {
public:
  enum CalendarType {
    T_GREGORIAN = 0,
    T_JULIAN = 1,
  };

...

Upvotes: 1

Views: 204

Answers (2)

inspector-g
inspector-g

Reputation: 4176

If you only have to compile a couple files as Objective-C++, then the answer that WrightsCS gave will work fine. However, if you have lots of files to compile this way, or think your project will get bigger in the future, you can change the compilation language for all files:

Go to the Build Settings for your target, look under the Language section for a setting called Compile Sources As. Usually it is set to "According to File Type" (which should work with the .mm extension, but I've seen bugs where it still compiles as Objective-C before). You can force it to "Objective-C++" by changing this setting.

Upvotes: 1

WrightsCS
WrightsCS

Reputation: 50727

You need to set -x objective-c++ as a Compiler Flag on the .mm file you are referring to.

enter image description here

Upvotes: 0

Related Questions