mixing -std=c99 and -std=c++0x

798 views
Skip to first unread message

Alex Cohn

unread,
Aug 29, 2012, 6:40:31 AM8/29/12
to android-ndk
NDK allows mixing C and C++ files in a single project (e.g. to create
a shared library). Unfortunately, it does not allow to specify C-
language specific compilation flags. This is rarely necessary, but one
case I found recently was when the C files expected -std=c99 and C++
depended on -std=c++0x.

Simply defining

LOCAL_CFLAGS += -std=c99
LOCAL_CPPFLAGS += -std=c++0x

would not work nicely, because each C++ compilation will issue the
warning
cc1plus: warning: command line option "-std=c99" is valid for C/
ObjC but not for C++

Luckily, I have found an ugly workaround: instead of setting
LOCAL_CFLAGS, add the following two lines to your Android.mk

LOCAL_C99_FILES := $(filter %.c, $(LOCAL_SRC_FILES))
TARGET-process-src-files-tags += $(call add-src-files-target-
cflags, $(LOCAL_C99_FILES), -std=c99)

This works for me for NDK r8b, but I hope there will be better ways in
the future.
I have made no effort to check compatibility of this hack with older
versions of NDK.

David Turner

unread,
Aug 29, 2012, 11:39:50 AM8/29/12
to andro...@googlegroups.com
The TARGET-xxx rules are implementation details of the NDK, don't rely on them from working in the future.
If this really is a problem, place the C and C++ files into different modules.


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Reply all
Reply to author
Forward
0 new messages