Opengl с библиотеками cmake и glew glfw3 и glm

У меня проблема с компиляцией этого примера в Ubuntu 12.04 LTS:

#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glfw3.h>
#include <glm/glm.hpp>

using namespace glm;

int main(){
if( !glfwInit() )
{
    fprintf( stderr, "Failed to initialize GLFW\n" );
    return -1;
}

glfwWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing
glfwWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // We want OpenGL 3.3
glfwWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL

// Open a window and create its OpenGL context
GLFWwindow* window; // (In the accompanying source code, this variable is global)
window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
if( window == NULL ){
    fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
    glfwTerminate();
    return -1;
}
glfwMakeContextCurrent(window);

// Initialize GLEW
glewExperimental=true; // Needed in core profile
if (glewInit() != GLEW_OK) {
    fprintf(stderr, "Failed to initialize GLEW\n");
    return -1;
}

glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

do{
    // Draw nothing, see you in tutorial 2 !

    // Swap buffers
    glfwSwapBuffers(window);
    glfwPollEvents();

} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
glfwWindowShouldClose(window) == 0 );

return 0;
}

Я пытался скомпилировать его, используя одну строку в терминале с соответствующими флагами, но всегда находил ошибки. На нескольких форумах я обнаружил, что лучше использовать cmake для поиска, компоновки и компиляции с использованием нужных мне библиотек, поэтому с помощью этот пример я попытался запрограммировать свои собственные списки cmake, получив такой код:

cmake_minimum_required(VERSION 2.8)


#Encontrando y linkeando GLEW
find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})
link_directories(${GLEW_LIBRARY_DIRS})
add_definitions(${GLEW_DEFINITIONS})
if(NOT GLEW_FOUND)
 message(Error " GLEW not found")
endif(NOT GLEW_FOUND)

#Encontrando y linkeando glfw3
find_package(GLFW REQUIRED)
include_directories(${GLFW_INCLUDE_DIRS})
link_directories(${GLFW_LIBRARY_DIRS})
add_definitions(${GLFW_DEFINITIONS})

if(NOT GLFW_FOUND)
        message(Error "GLFW not found")
endif(NOT GLFW_FOUND)

#Encontrando y linkeando glm

find_package(GLM REQUIRED)
include_directories(${GLM_INCLUDE_DIRS})
link_directories(${GLM_LIBRARY_DIRS})
add_definitions(${GLM_DEFINITIONS})

if(NOT GLM_FOUND)
        message(Error "GLM not found")
endif(NOT GLM_FOUND)

find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})

if(NOT OpenGL_FOUND)
        message(Error "OpenGL not found")
endif(NOT OpenGL_FOUND)

#Incluir archivos

add_executable(abrir main.cpp)

target_link_libraries(abrir ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} ${GLFW_LIBRARIES} ${GLM_LIBRARIES})

Но я получаю эти ошибки:

Could not find module FindGLEW.cmake or a configuration file for package GLEW.

Adjust CMAKE_MODULE_PATH to find FindGLEW.cmake or set GLEW_DIR to the
directory containing a CMake configuration file for GLEW.  The file will
have one of the following names:

GLEWConfig.cmake
glew-config.cmake



Error GLEW not found
CMake Error at CMakeLists.txt:14 (find_package):
Could not find module FindGLFW.cmake or a configuration file for package
GLFW.

Adjust CMAKE_MODULE_PATH to find FindGLFW.cmake or set GLFW_DIR to the
directory containing a CMake configuration file for GLFW.  The file will
have one of the following names:

GLFWConfig.cmake
glfw-config.cmake



ErrorGLFW not found
CMake Error at CMakeLists.txt:25 (find_package):
Could not find module FindGLM.cmake or a configuration file for package
GLM.

Adjust CMAKE_MODULE_PATH to find FindGLM.cmake or set GLM_DIR to the
directory containing a CMake configuration file for GLM.  The file will
have one of the following names:

GLMConfig.cmake
glm-config.cmake

Как я могу исправить эти ошибки? Или есть более простой способ решить проблему?


person user3403875    schedule 10.03.2014    source источник
comment
Вы пытались... найти glew-config.cmake/glfw-config.cmake и т. д. и соответствующим образом установить CMAKE_MODULE_PATH перед запуском cmake?   -  person Pavel Beliy    schedule 11.03.2014


Ответы (2)


Я знаю, что это "немного" поздно. Но если кто-то еще столкнулся с этой проблемой. Это то, что я сделал.

Я скопировал этот файл https://github.com/Groovounet/glm-deprecated/blob/master/util/FindGLM.cmake на моем компьютере, т.е. /home/user/Libs/cmake/FindGLM.cmake

Затем я добавил эту строку в свой CMakeLists.txt:

set(CMAKE_MODULE_PATH /home/user/Libs/cmake)

Итак, мои первые 3 строки моего файла:

cmake_minimum_required (VERSION 2.6)
project (test)
set(CMAKE_MODULE_PATH /home/user/Libs/cmake)

Затем я запускаю cmake и make, и у меня не было ошибок.

person vlavyb    schedule 06.01.2016
comment
Это работает для тех, кто пытается скомпилировать библиотеку Arrayfire и получает ошибки glm CMake. - person Jeremy Hajek; 29.12.2018

Я настоятельно рекомендую вам использовать Qt Creator для этого конкретного руководства. По крайней мере, я так делал. Для таких вещей всегда лучше использовать IDE. Я помню, что мне пришлось переписать некоторые части файла CMakeLists, чтобы правильно построить его для моей среды (например, я не хотел использовать AntTweakBar).

Инструкции по Qt Creator, представленные в этом руководстве, действительно хороши, и они должны работать на вас.

Кроме того, не забудьте установить каждый пакет, упомянутый в том руководстве, которое вы используете, включая CMake. Если я хорошо помню, они должны работать нормально :)

person BlastDV    schedule 11.03.2014