namespace "std" has no member "make_unique"

Oct 19, 2015 at 11:06 PM
Edited Oct 20, 2015 at 4:14 PM
As of the commit "c91c547e51f8" on Oct. 14, 2015 at 5:16 PM, a new line was inserted to Math/Math/

"auto workspace = m_workspace->pop_or_create(deviceId { return std::make_unique<GPUMatrix<ElemType>>(deviceId); });"

Since then, nvcc has kept on complaining "namespace "std" has no member "make_unique"" and compilation on Linux has never succeeded for any recent versions I've ever tried after that commit.

The option "std=c++14" is not acceptable for nvcc, though it is acceptable for gcc on version 4.9 or newer. I have not tried building CNTK on Windows yet so I cannot compare the results. Is there any OS-side modification needed for building the recent versions of CNTK on Linux?

Thanks a lot!
Oct 21, 2015 at 2:05 AM
std::make_unique was added in VS2013 so you should be able to build on Windows just fine.
On Linux std::make_unique was added starting gcc 4.9 so you can try using that version.
Alternatively, just remove/comment out #if line at basetypes.h, line 1053
(#if __GNUC__ >= 4 && __GNUC_MINOR__ < 9)
Oct 21, 2015 at 3:15 AM
Edited Oct 21, 2015 at 3:20 AM
Hi Alexey,

Thanks a lot and now I know where the problem comes from. I AM using GCC 4.9.2, so the extension for namespace std in basetypes.h did not take place. However, we need to add "--std=c++14" for the compilers instead. Unfortunately, "--std=c++14" only works for GCC (version 4.9 or newer) but not for NVCC, so compilation of still fails.

Thus, we may need to remove the #if line for basetypes.h, as this might be the only solution we have for Linux so far. Plus that introducing "--std=c++14" (even if we can do that for a future version of CUDA, say 8.0) will make the Makefile more complicated, as "--std=c++14" is not supported for GCC 4.8 or earlier versions, or CUDA versions before "8.0").


Oct 21, 2015 at 4:33 AM
Edited Oct 21, 2015 at 4:33 AM
Hi Tony,
Thanks for the update. I now understand why the code was building just fine in our Linux automated build system: we are using gcc 4.8.4 so #if worked in that case. I'll make the change tomorrow.

Oct 21, 2015 at 3:11 PM
Edited Oct 22, 2015 at 7:52 AM
Hi Alexey,

Your fix works well. However there might be a typo in your comment. It should be "c++14" rather than "c++11" that GCC and NVCC require (which is also the reason why we CANNOT do that now, since current version of NVCC cannot take "c++14", as mentioned in our previous posts).

Thanks a lot! :)

Oct 22, 2015 at 5:25 PM
Edited Oct 22, 2015 at 5:29 PM
Hi Tony,
I think my comment is unclear: what I meant to say is even with my fix, you still need to pass -std=c++11. You can argue that it is kind of obvious since unique_ptr itself was added in C++ 11 standard but I wanted to point it out anyway. I will re-write the comment to make it more clear.
In the current form, the code should compile both with -std=c++14 and without (I tested both scenarios on 4.9.2)

Oct 23, 2015 at 12:08 AM
Hi Alexy,

Thank you so much for clarifying this!