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!
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}
)
Related
I am unsure as to why I am greeted with "fatal error: 'GL/glew.h' file not found" when trying to build. My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 2.8)
project(ex_1)
add_executable(TorusDraw.out TorusDraw.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
find_package(GLEW REQUIRED)
find_package(GLM REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS} ${GLM_INCLUDE_DIRS} )
target_link_libraries( TorusDraw.out ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${GLEW_LIBRARY} ${GLM_LIBRARY} )
It looks as though it also cannot find glm
Image showing CLion not recognising glm and GLEW
Edit: I should mention the libraries were installed with homebrew
I am using CLion cmakelist.txt to compile but receive the following error. The program compiled with g++ but somehow lacks dependency when I am using cmake. anyone know how to solve this?
cmake_minimum_required(VERSION 3.19)
project(CTCWordBeamSearch_master)
find_package(PkgConfig)
pkg_check_modules(TensorFlow REQUIRED tensorflow)
link_directories(${TensorFlow_LIBRARY_DIRS})
include_directories(${TensorFlow_INCLUDE_DIRS})
add_compile_definitions(${TensorFlow_CFLAGS_OTHER})
set(CMAKE_CXX_STANDARD 14)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(.)
include_directories(cpp)
include_directories(cpp/proj)
include_directories(cpp/src)
include_directories(cpp/src/pybind)
include_directories(cpp/src/pybind/pybind11)
include_directories(cpp/src/pybind/pybind11/detail)
include_directories(cpp/src/utfcpp)
include_directories(cpp/src/utfcpp/utf8)
include_directories(data)
include_directories(doc)
include_directories(np)
include_directories(py)
include_directories(tf)
add_executable(CTCWordBeamSearch_master
...
)
target_link_libraries(CTCWordBeamSearch_master ${PYTHON_LIBRARIES})
target_link_libraries(CTCWordBeamSearch_master ${TensorFlow_LIBRARIES})
I'm trying to learn OpenGL from a tutorial, and I need to link SOIL2 to my project.
I tried to write my CMake like this:(all other libs are working, Cmake gets no error but I can't include SOIL2.h because of 'SOIL2.h' file not found). I'm working with Clion IDE.
cmake_minimum_required(VERSION 3.15)
project(OpenGL_Tutorial)
set(CMAKE_CXX_STANDARD 14)
add_executable(OpenGL_Tutorial main.cpp)
find_package(OpenGL REQUIRED)
find_package(SDL2 REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
find_library(SOIL2 lib/libsoil2.a)
include_directories(
${OPENGL_INCLUDE_DIRS}
${GLEW_INCLUDE_DIRS}
${GLFW_INCLUDE_DIRS}
${SDL2_INCLUDE_DIR}
)
target_link_libraries(OpenGL_Tutorial
${OPENGL_LIBRARY}
${GLEW_LIBRARY}
${GLFW_LIBRARIES}
${SDL2_LIBRARY}
${SOIL2_LIBRARY}
)
libsoil2.a is located in my lib directory in the project directory
(see project direcory image)
Thanks!
My project structure looks like this:
CMakeLists.txt
deps
glew
glfw
include
src
...
graphics
...
CMakeLists.txt
Two CMakeLists.txt files that deserve attention:
CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
project(noam_engine)
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
set(CMAKE_CXX_STANDARD 11)
set(NE_LIBRARIES common math graphics)
FOREACH(lib ${NE_LIBRARIES})
add_subdirectory(src/${lib})
ENDFOREACH(lib)
add_executable(noam_engine src/main.cpp)
if(OPENGL_FOUND AND GLEW_FOUND)
target_include_directories(noam_engine PUBLIC include ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIRS})
target_link_libraries(noam_engine ${NE_LIBRARIES})
endif()
src/graphics/CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
file(GLOB SRC "*.cpp")
add_library(graphics ${SRC})
if(OPENGL_FOUND AND GLEW_FOUND)
target_include_directories(graphics PUBLIC ${PROJECT_SOURCE_DIR}/include ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIRS})
target_link_libraries(graphics ${OPENGL_gl_LIBRARY} ${GLFW3_LIBRARY} ${GLEW_LIBRARIES})
message(STATUS "GLFW and GLEW successfully linked")
message(STATUS ${OPENGL_gl_LIBRARY})
message(STATUS ${GLFW3_LIBRARY})
message(STATUS ${GLEW_LIBRARIES})
else()
message(STATUS "Cannot find GL libraries")
endif()
In a few words I want to create a bunch of static libraries of the engine, in particular, link graphics library with GL's, and finally link all of them with the executable in a root CMakeLists.txt.
But I noticed that ${GLFW3_LIBRARY} is empty and I got a linker error, for example, when I call glfwInit(). I followed the guide during building and installation of GLFW
cmake .
make
make install
I believe headers and libraries are in /usr/local/*, but apparently CMake cannot find them or maybe I did something wrong.
The only hypothesis I have is that find_package doesn't know about glfw3Config.cmake which is in deps/glfw/*
I took the script from https://github.com/JoeyDeVries/LearnOpenGL/blob/master/cmake/modules/FindGLFW3.cmake and put it into cmake folder. Then in CMakeLists.txt I added
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
Now everything works properly
Thanks #Tsyvarev
I used this link to install OpenCV.
What works:
1.OpenCV works fine with python (running from terminal).
2.I can import opencv libraries in a single C++ program.
What does not work :
When the code is spread across multiple and you need to build it using CMake.
Here's my CmakeLists.txt :
1.cmake_minimum_required(VERSION 3.9)
2.project(Image_processing)
3.set(CMAKE_CXX_STANDARD 14)
4.find_package(OpenCV REQUIRED)
5.include_directories(/home/user/opencv/build)
6.add_executable(main main.cpp)
7.target_link_libraries(project_name ${OpenCV_LIBS})
Errors (can regenerate them by commenting lines 4,5 and 7 in above CMake file):
undefined reference to OpenCV functions.
CMake Error at CMakeLists.txt:7 (target_link_libraries):
Cannot specify link libraries for target "Image_processing" which is not
built by this project.
Correct it with:
cmake_minimum_required(VERSION 3.5)
project(Image_processing)
set(CMAKE_CXX_STANDARD 14)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(main main.cpp)
target_link_libraries(main ${OpenCV_LIBS})
In your CMakeLists.txt, the exe-name is not matching with the target-link-name. I modify the line, then it works on my PC.
The CMakeLists.txt of an OpenCV Project:
cmake_minimum_required(VERSION 3.5)
project(Image_processing)
set(CMAKE_CXX_STANDARD 14)
find_package(OpenCV REQUIRED)
#include_directories(/home/user/opencv/build)
add_executable(Image_processing main.cpp)
target_link_libraries(Image_processing ${OpenCV_LIBS})