QGLViewer simpleViewer example built with cmake no

2019-09-19 23:27发布

问题:

I'm trying to familiarize with QGLViewer (http://libqglviewer.com/) so I installed it (on Ubuntu 14.04) and I'm trying to run the simpleViewer (which is a provided example). Now, the code can be built using qmake, but I want to compile the code with cmake so I wrote the following 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})

I'm able to build the project but when I launch the executable this is the error I get:

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

I'd be glad if someone could explain me what's wrong!

Thanks!

回答1:

worked this way:

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}
)