YuvalNirkin / face_swap

End-to-end, automatic face swapping pipeline
GNU General Public License v3.0
822 stars 203 forks source link

error: 'make_unique' is not a member of 'std' #7

Closed daili0015 closed 7 years ago

daili0015 commented 7 years ago

When i make on ubuntu14.04 like this: —————

mkdir build
cd build
cmake ..
make all

————— Error occurs:

**`[ 54%] Building CXX object face_swap/CMakeFiles/face_swap.dir/cnn_3dmm_expr.cpp.o
/home/face_swap-master/face_swap/cnn_3dmm_expr.cpp: In constructor 'face_swap::CNN3DMMExpr::CNN3DMMExpr(const string&, const string&, const string&, const string&, bool, bool, bool, int)':

/home/face_swap-master/face_swap/cnn_3dmm_expr.cpp:29:20: error: 'make_unique' is not a member of 'std'
         fservice = std::make_unique<FaceServices2>();
                    ^~~

/home/face_swap-master/face_swap/cnn_3dmm_expr.cpp:29:50: error: expected primary-expression before '>' token
         fservice = std::make_unique<FaceServices2>();
                                                  ^

/home/face_swap-master/face_swap/cnn_3dmm_expr.cpp:29:52: error: expected primary-expression before ')' token
         fservice = std::make_unique<FaceServices2>();
                                                    ^

make[2]: *** [face_swap/CMakeFiles/face_swap.dir/cnn_3dmm_expr.cpp.o] Error 1

make[1]: *** [face_swap/CMakeFiles/face_swap.dir/all] Error 2

make: *** [all] Error 2**
`

————— I've searched on the Net , mostly said this's caused by a low g++(gcc)'s version, std::make_unique wasn't supposed until C++14. But i 'm using g++ 6.3, not a old version. ————— Being stucked here for 2days already , sad,grieved,helpless,despaired u 2904522468 2402474229 fm 214 gp 0

————— Without help , i am considering ending my poor life like this : ( 1 ————— ps : All the dependencies have been satisfied except Qt5, but i made 3 changes and cmake successed: 1、IN face_swap/CMakeLists.txt
option(WITH_QT "Qt" ON) ——> option(WITH_QT "Qt" OFF) 2、IN face_swap/face_swap_batch/CMakeLists.txt Qt5::Widgets ——># Qt5::Widgets 3、IN face_swap/face_swap_image/CMakeLists.txt Qt5::Widgets ——># Qt5::Widgets

I don't know are there relationships between my modifications and such error, i don't think there are.

jungerschwarz commented 7 years ago

I've been bothered just like you.waiting for the solution.

YuvalNirkin commented 7 years ago

This problem with make_unique can only happen when C++14 is not enabled. It could be that CMake found the old version of g++ which doesn't support C++14. If you can't solve this issue just replace every occurrence of

std::make_unique<T>(...)

with the following:

std::unique_ptr<T>(new T(...))

If you disable Qt you won't be able to build the examples. But Qt is only being used to create an off screen OpenGL context, so if you can't make it work you can replace the following code snippet in the face_swap_image or face_swap_batch applications:

// Intialize OpenGL context
QApplication a(argc, argv);

QSurfaceFormat surfaceFormat;
surfaceFormat.setMajorVersion(1);
surfaceFormat.setMinorVersion(5);

QOpenGLContext openGLContext;
openGLContext.setFormat(surfaceFormat);
openGLContext.create();
if (!openGLContext.isValid()) return -1;

QOffscreenSurface surface;
surface.setFormat(surfaceFormat);
surface.create();
if (!surface.isValid()) return -2;

openGLContext.makeCurrent(&surface);

With any other code that initializes an OpenGL 1.5 context, like OSMesa or GLUT. You will then have to remove anything QT related in the CMake files.

For example try this (not tested):

// Initialize OpenGL context
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitContextVersion(1, 5);
glutInitContextFlags(GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG);
glutInitWindowSize(width, height);
glutCreateWindow("face_swap_image");

Cheer up and good luck!

daili0015 commented 7 years ago

Thank U very much ! Problem have been solved. 1、error: 'make_unique' is not a member of 'std' Still can't solve this issue with g++ version, i replace std::make_unique<T>(...) With : std::unique_ptr<T>(new T(...)) and no more error now. 2、Qt can be found now by adding path to "/home/face_swap-master/CMakeLists.txt" img 306a

swayfreeda commented 6 years ago

I have successfully solved this problem on ubuntu 14.04 x64 make_unique can be used only when >=gcc-5 g++-5 is installed and c++14 is enabled.

  1. install gcc-5 g++-5 (http://www.cnblogs.com/loadofleaf/p/5667989.html)
  2. add "SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") " to the CMakeLists.txt