Project

General

Profile

Actions

Support #1244

closed

Which is the best way to define macro "__cplusplus" when I use crystax?

Added by Mario Li over 5 years ago. Updated over 5 years ago.

Status:
Invalid
Priority:
Normal
Category:
-
Target version:
-
Start date:
01/31/2016
Due date:
% Done:

0%

Estimated time:
CPU Architecture:
arm
Host OS:
Windows
Toolchain:
gcc-5
Android version:
5.0 (android-21)
CrystaX Version:

Description

!http://7xoj7k.com1.z0.glb.clouddn.com/16-1-31/8273847.jpg!

When I use crystax, I still can't use C11.
Finally I find the reason is the macro "__cplusplus" still not defined.
I defined the following options in file "Application.mk"

APP_PLATFORM := android-16
APP_ABI := armeabi-v7a
APP_STL := gnustl_static

NDK_TOOLCHAIN_VERSION=5
APP_CPPFLAGS += -fno-rtti -fexceptions
APP_CPPFLAGS +=-fpermissive
APP_CPPFLAGS += -std=c++11

What else should I do to make C11 correctly work?


Files

__cplusplus.png View __cplusplus.png 63.4 KB Mario Li, 01/31/2016 05:08 PM
test_macro_cplusplus.zip test_macro_cplusplus.zip 44.8 KB minimal example Mario Li, 02/02/2016 05:01 AM

Related issues

Has duplicate CrystaX NDK - Support #1251: Which is the best way to define macro "__cplusplus" when I use crystax?Duplicated02/02/2016

Actions
Actions #1

Updated by Dmitry Moskalchuk over 5 years ago

  • Status changed from Open to Waiting for feedback
  • Assignee set to Dmitry Moskalchuk

This macro is automatically defined if you use C++ compiler (i.e. @g++@ or @gcc -x c++@) . Obviously, you're doing something wrong, if it is undefined. The only reason I can guess right now is that you're compiling it in non-C++ mode. The simplest way to ensure that C++ compiler is used is making all sources ending by @.cpp@ extension. If this is not the case, or doesn't help, please provide minimal example, reproducing the problem.

Actions #2

Updated by Mario Li over 5 years ago

Dmitry Moskalchuk wrote:

This macro is automatically defined if you use C++ compiler (i.e. @g++@ or @gcc -x c++@) . Obviously, you're doing something wrong, if it is undefined. The only reason I can guess right now is that you're compiling it in non-C++ mode. The simplest way to ensure that C++ compiler is used is making all sources ending by @.cpp@ extension. If this is not the case, or doesn't help, please provide minimal example, reproducing the problem.

I upload the minimal example, just make a new project "Android Application Project", then "Add native support".
Add the file "Appllication.mk".
After I click "build project" , all the header file (.h) can be correctly found.
Then I jump into the header file , I find that the macro "__cplusplus" still can not be found. Just like the picture I show above.

Actions #3

Updated by Mario Li over 5 years ago

Unfortunately, I can not find the file I just uploaded.
I try to upload the minimal example again.

Actions #4

Updated by Mario Li over 5 years ago

I still can not find the minimal example, maybe something is wrong with Redmine?
I have to upload the file to a network disk:

http://pan.baidu.com/s/1nujEwh7

Actions #5

Updated by Dmitry Moskalchuk over 5 years ago

Mario Li wrote:

I still can not find the minimal example, maybe something is wrong with Redmine?

Here is limitation for file size. It must be less than 4 MB. Probably you're exceeding this limit by including built binaries. Please cleanup everything and provide minimal example.

I have to upload the file to a network disk:

http://pan.baidu.com/s/1nujEwh7

I can't download that file, my browser report about harmful script on that page.

Actions #6

Updated by Mario Li over 5 years ago

I delete libs and obj folders to make the .zip file smaller, this time I think I will success!!!

Actions #7

Updated by Dmitry Moskalchuk over 5 years ago

  • Has duplicate Support #1251: Which is the best way to define macro "__cplusplus" when I use crystax? added
Actions #8

Updated by Dmitry Moskalchuk over 5 years ago

  • Status changed from Waiting for feedback to In Progress
Actions #9

Updated by Dmitry Moskalchuk over 5 years ago

  • Status changed from In Progress to Invalid

Mario Li wrote:

I delete libs and obj folders to make the .zip file smaller, this time I think I will success!!!

Your example works just fine. I've added this at begin of @jni/test_macro_cplusplus.cpp@:

#if !defined(cplusplus)
#error "
cplusplus is not defined!"
#endif

And it compiles without any errors:

$ /opt/android/crystax-ndk-10.3.1/ndk-build
[armeabi-v7a] Compile++ thumb: test_macro_cplusplus <= test_macro_cplusplus.cpp
[armeabi-v7a] SharedLibrary : libtest_macro_cplusplus.so
[armeabi-v7a] Install : libcrystax.so => libs/armeabi-v7a/libcrystax.so
[armeabi-v7a] Install : libtest_macro_cplusplus.so => libs/armeabi-v7a/libtest_macro_cplusplus.so

I presume you've been mistaken by your IDE, which for some reason doesn't handle C++ code properly (looking on screenshot, I suppose it's Eclipse). Maybe it's wrong Eclipse settings, maybe it's Eclipse bug (it have problems with parsing more-or-less non-trivial C++ code for years). You shouldn't rely on IDE logic, doing such conclusions. Compiler is the only one whose behaviour is important.

This is definitely not the CrystaX NDK issue, so closing this ticket as "Invalid".

Actions

Also available in: Atom PDF