C++11 support in NativeLibrary for Android - c++

I'm trying to create a native library in C++, which I can use in Android.
I've created a project in Visual Studio 2017: Dynamic Shared Library (Android), and added my cpp code.
Though some of the code is running C++11, and I'd really like to keep it that way.
When I compile, I get the error:
This file requires compiler and library support for the ISO C++ 2011 standard.
This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
So I first tried going to Project->Properties->C/C++->Language->C++ Language Standard, and set the options as following:
'
When I compile now, I get exactly the same error. So I tried manually adding the -std=c++11 flag under additional options, though still getting the error.
Why is the compiler not willing to compile using the ++11 standard, and what can I do to fix this? I know it's experimental, but it should at least try to compile.
Best regards

The problem was solved, when I changed the settings to be for All Platforms, and not just ARM.

Related

Do any compilers currently support C++20?

I purchased a book recently entitled beginning C++20. I was looking to begin learning c++ though I now realize that I can't find a compiler that can run the code in the book as I get an error since the compiler I'm using (xcode) does not support c++ 20. I'm wondering if there are any compilers that I can run on my mac that support c++20.
gcc version 8 and up supports some of C++20; you can try using that.
It should also be noted that Xcode isn't a compiler, but instead an IDE that should be using clang as the actual compiler. Clang also currently has support for some of the C++ 20 features. To use them the -std=c++20 flag will still be needed.
Here can you find the currently implemented feature support of the GCC compiler of the C++20 specification:
GCC Link
But you need to enable it in your console command or add this to your toolchain: "-std=c++20"

C++ versions, what they mean, how to update them

Is the c++ version you use tied to the version of compiler you have or IDE?
If it isn't either of those, how do I use c++ 11 on my IDE? How do i update what C++ version i use in my programs?
How do I check what version I'm using?
I know that printing the __cplusplus variable can tell me what version I'm using, but this doesn't answer my other questions, neither does it answer my third question, because: https://stackoverflow.com/a/14131551/10938047
Found this question, with the answer containing an outdated link.
Visual Studio 2012 __cplusplus and C++ 11
The C++ version you can use is obviously tied to the compiler you use. If your compiler doesn't support some newer standard then of course you cannot use it.
As for IDEs; some IDEs are tied to a specific compiler, some can use different ones.
Some compilers support multiple language versions but require you to explicitly enable anything newer than what they enable by default. For example; most older versions of GCC support C++17 just fine, but default to C++11 or C++14 unless you tell them to enable C++17 support via the -std=c++17 command line option.

Which C++ standard for I have for g++ compiler?

I work on the Code::Blocks IDE but I'm currently planning to use Sublime editor + some compiler.
In C: B, I have the MinGW g++ compiler (not sure of the version).
How do I know which C++ standard (14 or 11 or the previous ones) I'm using? Also, how do I change the C++ standard and get the one I want? (I need 14 actually). Please tell for both C::B and when I'm installing the compiler separately for Sublime.
C++14 should be the default for GCC since version 6.0. Before 6.0, the default is C++98. Open a command prompt and type g++ --version to see your version.
To change the version flag, go to Settings -> Compiler (or something like that) and look at the list of compiler flags. Check the one that looks like "Have g++ follow the ISO ... C++14 standard".
For other IDEs, find the compiler/build settings, which might or might not be separate for each project, look through them, and select the standard. The flag for it is --std=c++14 by the way.
This might help.

codeblocks shows error: This file requires support for the ISO C++ 2011 standard

I want to use poisson_distribution template in my C++ code (included in random header), but cant find a way to compile it without error
My codeblocks shows an error
This file requires compiler and library support for the \
ISO C++ 2011 standard. This support is currently experimental, and must be \
enabled with the -std=c++11 or -std=gnu++11 compiler options.
I remember while installing codeblocks I installed only gnu c/c++ compiler. Can anyone explain me how to update my compiler to standard ISO C++ 2011 standard or suggest an alternative.
Thanks in advance...
You don't need to update the compiler. You just need to set it to C++11 mode.
How can I add C++11 support to Code::Blocks compiler?
A simple option would be to write
-std=c++11
As part of the other compiler options flags or directly in your Makefile.
Note that some projects may require -std=gnu++11 which is like C++11 but has some GNU extensions enabled.
Settings > Compiler >
select the checkbox:
'Have g++ follow the C++11 ISO C++ language standard'

Porting from Code::Blocks to Visual Studio 2010

Say I have a open source C::B C++ (non-C++11, perfectly compatible with the 1998 ISO standard) project I've downloaded which is using MinGW/GCC (TDM-1 4.7.1 or 4.7.2 - doesn't work with newest version),; can I port the source files from it to Visual Studio 2010 and be able to make it work without massive code rewriting? Or there are certain cases in which it won't be possible? Or it depends on various things?
EDIT:
The code relies on additional external utilities and libraries such as:
Lua
SDL 2.0 + SDL Image 2.0
OpenGL
The most General and correct response is: It depends on various things.
What kind of project are you refering to? Is it wxWidget, QT4, GTK+, OpenGL?
How much do you use c++11?
Assuming that we are talking about a simple Console Application the easiest way to verify whether you can migrate to MSVC2010 is to switch compiler inside Code::Blocks project.
Select Project->Build Option... and under Selected compiler choose Microsoft Visual Studio C++ 2010. Afterwards try to recompile. The warning and errors will show you how easy will be the porting.
Of course you have to install Code::Blocks with MSVC2010 too.
EDIT: The OpenGL library is supported by MSVC2010 and libsdl has VC development libraries. However, things seem to be more complex with Lua. My guess is that you might start a substantial porting work here.
If the project was written using portable C++98 code you shouldn't have too much trouble. First, I would check you can compile in GCC with -std=c++98 -pedantic flags and fix any warnings to ensure you are not relying on any GCC extensions.
It also depends on the portability of any required libraries.
Try it!
If your code is standard-compliant and does not rely on any GCC extensions or GCC-specific libraries, then you should be fine out-of-the-box.
Note though that different compilers support C++ in different ways; for example, even Visual Studio 2013 has only passing C++11 support so if your program is a C++11 program with things like ranged-for and initializer lists in it then, depending on the version you're using, it's just not going to work without those pieces of code being rewritten to look more like C++03.
I actually made a mistake:
C::B indeed told me there were multiple errors in the compilation attempt with the MSVC2010 compiler, because the code included many Unix-only libraries, too intricately so to be easily avoided. Thus, I'm thinking of either making MinGW/GCC work in Visual Studio itself or sticking with C::B.
(Continues here: POSIX Headers (from MinGW project) in Visual Studio 2013)