The below code is copied from http://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique
main.cpp (no pcl related code)
``````
struct Vec3{
int x, y, z;
Vec3() : x(0), y(0), z(0) { }
Vec3(int x, int y, int z) :x(x), y(y), z(z) { }
friend std::ostream& operator<<(std::ostream& os, Vec3& v) {
return os << '{' << "x:" << v.x << " y:" << v.y << " z:" << v.z << '}';
}
};
int main(){
std::unique_ptr
}
``````
CMakeLists.txt (if I don't link to pcl everything compiles fine, but if I link to pcl as shown below)
``````
cmake_minimum_required(VERSION 3.5)
project(Example)
set(PROJECT_SRCS
${PROJECT_SOURCE_DIR}/main.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
find_package( PCL REQUIRED )
add_executable(${PROJECT_NAME} ${PROJECT_SRCS})
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${PCL_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${PCL_LIBRARIES})
``````
after
``````
mkdir build
cd build
cmake ..
make
error: ‘make_unique’ is not a member of ‘std’
std::unique_ptr
``````
I am very puzzled on why simply linking to pcl will make the compiler think make_unique is not a member of std. Does PCL redefine make_unique somewhere?
Did you compile PCL yourself? If so, did you set -std=c++1y during the library compilation?
Reopen if needed although this is just issues with c++11 which we don't officially support.
@taketwo No I did not alter any CMake options while building PCL myself. Even if PCL is not built with -std=c++1y, as long as my downstream project has the -std=c++1y it should still compile. I have a lot of other external libraries (For example: OpenCV) that I am linking to that is also not compiled with C++11 and it doesn't cause any issues.
@SergioRAgostinho I am not asking PCL to support c++11. If my downstream project compiles with c++11 flag, why would linking with PCL cause any problem? Please reopen
I understand your point now.
What's the output of make with verbose activate?
@SergioRAgostinho with make VERBOSE=1
/usr/bin/cmake -H/home/ubuntu/test -B/home/ubuntu/test/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/ubuntu/test/build/CMakeFiles /home/ubuntu/test/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/ubuntu/test/build'
make -f CMakeFiles/Example.dir/build.make CMakeFiles/Example.dir/depend
make[2]: Entering directory '/home/ubuntu/test/build'
cd /home/ubuntu/test/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/ubuntu/test /home/ubuntu/test /home/ubuntu/test/build /home/ubuntu/test/build /home/ubuntu/test/build/CMakeFiles/Example.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/ubuntu/test/build'
make -f CMakeFiles/Example.dir/build.make CMakeFiles/Example.dir/build
make[2]: Entering directory '/home/ubuntu/test/build'
[ 50%] Building CXX object CMakeFiles/Example.dir/main.cpp.o
/usr/bin/c++ -DvtkDomainsChemistry_AUTOINIT="1(vtkDomainsChemistryOpenGL2)" -DvtkIOExport_AUTOINIT="1(vtkIOExportOpenGL2)" -DvtkRenderingContext2D_AUTOINIT="1(vtkRenderingContextOpenGL2)" -DvtkRenderingCore_AUTOINIT="3(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingOpenGL2)" -DvtkRenderingOpenGL2_AUTOINIT="1(vtkRenderingGL2PSOpenGL2)" -DvtkRenderingVolume_AUTOINIT="1(vtkRenderingVolumeOpenGL2)" -isystem /usr/include/vtk-8.1 -isystem /usr/include/pcl-1.8 -isystem /usr/include/eigen3 -isystem /usr/include/openni2 -std=c++1y -std=gnu++11 -o CMakeFiles/Example.dir/main.cpp.o -c /home/ubuntu/test/main.cpp
/home/ubuntu/test/main.cpp: In function ‘int main()’:
/home/ubuntu/test/main.cpp:21:30: error: ‘make_unique’ is not a member of ‘std’
std::unique_ptr<Vec3> v1 = std::make_unique<Vec3>();
^
/home/ubuntu/test/main.cpp:21:51: error: expected primary-expression before ‘>’ token
std::unique_ptr<Vec3> v1 = std::make_unique<Vec3>();
^
/home/ubuntu/test/main.cpp:21:53: error: expected primary-expression before ‘)’ token
std::unique_ptr<Vec3> v1 = std::make_unique<Vec3>();
^
CMakeFiles/Example.dir/build.make:62: recipe for target 'CMakeFiles/Example.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/Example.dir/main.cpp.o] Error 1
make[2]: Leaving directory '/home/ubuntu/test/build'
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Example.dir/all' failed
make[1]: *** [CMakeFiles/Example.dir/all] Error 2
make[1]: Leaving directory '/home/ubuntu/test/build'
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Compilation command has: -std=c++1y -std=gnu++11. The latter flag wins, so you get C++11 that does not have make_unique.
Which VTK version you have? I know they recently switched to C++11, maybe this flag comes from them?
Is -std=gnu++11 appended by PCL? Because if I comment out target_link_libraries(${PROJECT_NAME} ${PCL_LIBRARIES}) and do make VERBOSE=1, here is the output
/usr/bin/cmake -E cmake_progress_start /home/ubuntu/test/build/CMakeFiles /home/ubuntu/test/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/ubuntu/test/build'
make -f CMakeFiles/Example.dir/build.make CMakeFiles/Example.dir/depend
make[2]: Entering directory '/home/ubuntu/test/build'
cd /home/ubuntu/test/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/ubuntu/test /home/ubuntu/test /home/ubuntu/test/build /home/ubuntu/test/build /home/ubuntu/test/build/CMakeFiles/Example.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/ubuntu/test/build'
make -f CMakeFiles/Example.dir/build.make CMakeFiles/Example.dir/build
make[2]: Entering directory '/home/ubuntu/test/build'
[ 50%] Building CXX object CMakeFiles/Example.dir/main.cpp.o
/usr/bin/c++ -DvtkDomainsChemistry_AUTOINIT="1(vtkDomainsChemistryOpenGL2)" -DvtkIOExport_AUTOINIT="1(vtkIOExportOpenGL2)" -DvtkRenderingContext2D_AUTOINIT="1(vtkRenderingContextOpenGL2)" -DvtkRenderingCore_AUTOINIT="3(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingOpenGL2)" -DvtkRenderingOpenGL2_AUTOINIT="1(vtkRenderingGL2PSOpenGL2)" -DvtkRenderingVolume_AUTOINIT="1(vtkRenderingVolumeOpenGL2)" -isystem /usr/include/vtk-8.1 -isystem /usr/include/pcl-1.8 -isystem /usr/include/eigen3 -isystem /usr/include/openni2 -std=c++1y -o CMakeFiles/Example.dir/main.cpp.o -c /home/ubuntu/test/main.cpp
[100%] Linking CXX executable Example
/usr/bin/cmake -E cmake_link_script CMakeFiles/Example.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++1y CMakeFiles/Example.dir/main.cpp.o -o Example
make[2]: Leaving directory '/home/ubuntu/test/build'
[100%] Built target Example
make[1]: Leaving directory '/home/ubuntu/test/build'
/usr/bin/cmake -E cmake_progress_start /home/ubuntu/test/build/CMakeFiles 0
Ah, so it could be a VTK problem... my VTK was also built from source from the latest master.
Yeah, I think VTK is the main suspect here. Try to link against some VTK library without linking to PCL.
Confirmed that this is a VTK problem. I will file an issue over there.
For reference, VTK ticket: https://gitlab.kitware.com/vtk/vtk/issues/17118
Once we switch to a newer C++ standard in PCL we will face the same problem and may learn from their solution.
@taketwo The right way to solve it is add set(CMAKE_CXX_STANDARD 14) in the downstream project instead of set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y"). Credit to https://github.com/aws/aws-sdk-cpp/issues/674
Thanks! For the record, this is available in CMake since version 3.1.
Reproduced with PCL 1.8.1 installed under Ubuntu 18.04 with apt. Solution offered by @taketwo above worked for me.