I have a problem using threads in my application. I am writing C++ files, that are used in Android, so they are compiled with NDK and cmake. I have no idea how to load thread support. Is there anything i have to write into CMakeLists or the MakeFile or something like that? I am an absolute beginner in writing C++ code...
Asked
Active
Viewed 1,923 times
1
-
This is the code i get after the make, after including
:C:/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/c++0x_warning.h:32:2: error: #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. – Markus Steppberger Mar 25 '14 at 10:34 -
Did you try adding one of the flags that were suggested to you? – Michael Mar 25 '14 at 10:40
-
I don't know exactly how to do it... I also read somewhere, that with compiler version 4.6 you have to do anything else... – Markus Steppberger Mar 25 '14 at 10:44
-
Add it to `LOCAL_CPPFLAGS` in your Android.mk – Michael Mar 25 '14 at 10:46
-
1C++ offers native multi threading support since C++ 11, you'll need GCC 4.8 to reach such level of features (maybe 4.7?). You can refer to [this other SO answer](http://stackoverflow.com/questions/10984442/how-to-detect-c11-support-of-a-compiler-with-cmake) for further details on that. – opatry Mar 25 '14 at 10:55
-
Maybe i really don't know what i am doing, but i dont have a Android.mk. I am writing C++ files and i do compile them with cmake and the NDK cpp compiler... The files run on Android, but don't communicate directly with any Java code, so there is no JNI used. These files are only loaded by a HMI software on the Android system. – Markus Steppberger Mar 25 '14 at 10:56
-
Do the C++ files you're writing allow you to use pthreads features instead, or does it have to be the C++
? – fadden Mar 25 '14 at 14:40 -
I think i can use pthreads too, but i don't get them working as well... the main task of my C++ code is to listen and write to a socket, so which type of thread i use is not important in my opinion... The main things in my architecture happen in java, so i want to have the C++ part as simple as possible, because i don't really know anything about C++ coding.. – Markus Steppberger Mar 26 '14 at 12:25
2 Answers
0
If you are using Cmake for Android, e.g. https://github.com/taka-no-me/android-cmake, then to enable std::thread
you should specify
ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.8
and
ANDROID_STL=gnustl_static
(or gnustl_shared
),

Alex Cohn
- 56,089
- 9
- 113
- 307
0
To enable C++11 thread class (std::thread
) with Cmake simply add to your CMakeLists.txt
the following line:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror")
Full example here.

Roberto Leinardi
- 10,641
- 6
- 65
- 69