参考官网安装教程,(sudo 安装,教程在这里)。安装好MRPT后,写了一个测试程序,报错如下
/usr/include/mrpt/base/include/mrpt/utils/CConfigFileBase.h:79: error: ‘enable_if_t’ in namespace ‘std’ does not name a template type
typename = std::enable_if_t
发现 enable_if_t 是cpp14里的功能,cpp11只有enable_if。
所以改CMakeLists里面cpp版本选择
set( CMAKE_CXX_FLAGS “-std=c++11”)
改为
set( CMAKE_CXX_FLAGS “-std=c++14”)
编译成功。
CMakeLists.txt
cmake_minimum_required( VERSION 2.8 )
project ( MRPT_example )
set( CMAKE_CXX_FLAGS "-std=c++14")
FIND_PACKAGE( MRPT REQUIRED base gui) # WARNING: Add all the MRPT libs used by your program: "gui", "obs", "slam",etc.
ADD_EXECUTABLE( example1 test.cpp )
TARGET_LINK_LIBRARIES(example1 ${MRPT_LIBS})
test.cpp
/* **************************************
* mrpt使用
*
* ***************************************/
#include <iostream>
//#include <type_traits>
#include <mrpt/gui/CDisplayWindowPlots.h>
using namespace std;
int main(int argc, char** argv)
{
mrpt::gui::CDisplayWindowPlots win("path2D",400,400);
win.hold_on();
win.setPos(1300,0);
std::vector<double> x,y;
for (int i = 0; i < 1000; i++)
{
double tempx = 10.0*i-500;
double tempy = 9*i-500;
x.push_back(tempx);
y.push_back(tempy);
}
win.plot(x,y,"r.3");
win.axis_fit();
win.axis_equal(true);
while(1);
return 0;
}
效果图