I am trying to compile the following thread pool program posted on code review to test it.
https://codereview.stackexchange.com/questions/55100/platform-independant-thread-pool-v4
But I am getting the errors
threadpool.hpp: In member function ‘std::future<decltype (task((forward<Args>)(args)...))> threadpool::enqueue_task(Func&&, Args&& ...)’:
threadpool.hpp:94:28: error: ‘make_unique’ was not declared in this scope
auto package_ptr = make_unique<task_package_impl<R, decltype(bound_task)>> (std::move(bound_task), std::move(promise));
^
threadpool.hpp:94:81: error: expected primary-expression before ‘>’ token
auto package_ptr = make_unique<task_package_impl<R, decltype(bound_task)>>(std::move(bound_task), std::move(promise));
^
main.cpp: In function ‘int main()’:
main.cpp:9:17: error: ‘make_unique’ is not a member of ‘std’
auto ptr1 = std::make_unique<unsigned>();
^
main.cpp:9:34: error: expected primary-expression before ‘unsigned’
auto ptr1 = std::make_unique<unsigned>();
^
main.cpp:14:17: error: ‘make_unique’ is not a member of ‘std’
auto ptr2 = std::make_unique<unsigned>();
^
main.cpp:14:34: error: expected primary-expression before ‘unsigned’
auto ptr2 = std::make_unique<unsigned>();
This question is related to
c++
c++11
compiler-errors
c++14
unique-ptr
If you have latest compiler, you can change the following in your build settings:
C++ Language Dialect C++14[-std=c++14]
This works for me.
In my case I was needed update the std=c++
I mean in my gradle file was this
android {
...
defaultConfig {
...
externalNativeBuild {
cmake {
cppFlags "-std=c++11", "-Wall"
arguments "-DANDROID_STL=c++_static",
"-DARCORE_LIBPATH=${arcore_libpath}/jni",
"-DARCORE_INCLUDE=${project.rootDir}/app/src/main/libs"
}
}
....
}
I changed this line
android {
...
defaultConfig {
...
externalNativeBuild {
cmake {
cppFlags "-std=c++17", "-Wall" <-- this number from 11 to 17 (or 14)
arguments "-DANDROID_STL=c++_static",
"-DARCORE_LIBPATH=${arcore_libpath}/jni",
"-DARCORE_INCLUDE=${project.rootDir}/app/src/main/libs"
}
}
....
}
That's it...
This happens to me while working with XCode (I'm using the most current version of XCode in 2019...). I'm using, CMake for build integration. Using the following directive in CMakeLists.txt fixed it for me:
set(CMAKE_CXX_STANDARD 14)
.
Example:
cmake_minimum_required(VERSION 3.14.0)
set(CMAKE_CXX_STANDARD 14)
# Rest of your declarations...
If you are stuck with c++11, you can get make_unique
from abseil-cpp, an open source collection of C++ libraries drawn from Google’s internal codebase.
1.gcc version >= 5
2.CXXFLAGS += -std=c++14
3. #include <memory>
Source: Stackoverflow.com