snowdragon
snowdragon

Reputation: 753

NDK: Compile c++ files with .mm extension

I have some C++ source files (with .mm extension) in an XCode project. I'm trying to compile only those that are pure C++ (no objc syntax or cocoa runtime used) and compile them in an Android NDK build (NDK r8d). The problem seems to be that g++ will not even consider .mm files as C++ and will fail with:

arm-linux-androideabi-g++: error: Objective-C++ compiler not installed on this system

I tried:
1. LOCAL_CPP_EXTENSION := .mm (in Android.mk) - doesn't help.
2. Search g++ documentation on how to accept custom file extensions - couldn't find any.

I'd really like to find a way to force NDK/g++ to accept .mm files, but open to other ideas like:

  1. copy & rename .mm to .cpp for the Android project - I don't like this since it complicates the build and version control, but it seems like the most basic thing that could work.
  2. build this as a static lib (using xcode) - I tried going there, but I wasn't sure which architecture to build for, or if it even makes sense.
  3. Others?

Does anyone have some experience or ideas on this? Thanks.

Solution (see accepted answer)
LOCAL_CFLAGS += -x c++

Upvotes: 2

Views: 2618

Answers (2)

Seva Alekseyev
Seva Alekseyev

Reputation: 61396

Despite the accepted answer, I'd still say that renaming the files to .CPP would be the right thing to do. What's so controversial about making the extension match the content? Xcode would be fine with compiling C++ files, and as a bonus, it'll protect you from accidentally polluting it with Objective C++ on the iOS side.

Upvotes: 1

Viktor Latypov
Viktor Latypov

Reputation: 14467

Add the "-x c++" option to $CFLAGS variable in .mk file. This should force GCC to use the C++ compiler.

EDIT: sorry for the typo, "-x" option, not "-c" and "c++", not "cpp"

Upvotes: 2

Related Questions