用cmake构建的QGLViewer simpleViewer示例未运行

时间:2016-09-07 12:03:34

标签: c++ build cmake realloc qglviewer

我试图熟悉QGLViewer(http://libqglviewer.com/),所以我安装了它(在Ubuntu 14.04上),我试图运行simpleViewer(这是一个提供的示例)。现在,代码可以使用qmake构建,但我想用cmake编译代码,所以我编写了以下CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)
PROJECT(simple_viewer)

SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)

FIND_PACKAGE(OpenGL REQUIRED)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE})

FIND_PACKAGE(QGLViewer REQUIRED)
INCLUDE_DIRECTORIES(${QGLVIEWER_INCLUDE_DIR})

FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
INCLUDE_DIRECTORIES(${QT_INCLUDES})

ADD_EXECUTABLE(${PROJECT_NAME} main.cpp simpleViewer.cpp)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${QT_LIBRARIES} ${OPENGL_LIBRARIES} ${QGLVIEWER_LIBRARY})

我能够构建项目但是当我启动可执行文件时,这是我得到的错误:

 dede@dede-P35V2:~/src/simple_viewer/build$ ./simple_viewer 
 *** Error in `./simple_viewer': realloc(): invalid pointer: 0x00007f64d34df840 *** Aborted

如果有人能解释我的错误,我会很高兴!

谢谢!

1 个答案:

答案 0 :(得分:0)

以这种方式工作:

cmake_minimum_required(VERSION 2.6)
PROJECT(simple_viewer)

SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)

FIND_PACKAGE(OpenGL REQUIRED)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE})

FIND_PACKAGE(QGLViewer REQUIRED)
INCLUDE_DIRECTORIES(${QGLVIEWER_INCLUDE_DIR})

FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
INCLUDE_DIRECTORIES(${QT_INCLUDES})

ADD_EXECUTABLE(${PROJECT_NAME} main.cpp simpleViewer.cpp)

TARGET_LINK_LIBRARIES(${PROJECT_NAME}
  ${QGLVIEWER_LIBRARY} 
  ${QT_QTXML_LIBRARY} 
  ${QT_QTOPENGL_LIBRARY} 
  ${QT_QTGUI_LIBRARY} 
  ${QT_QTCORE_LIBRARY} 
  ${OPENGL_gl_LIBRARY} 
  ${OPENGL_glu_LIBRARY}
)