我在Ubuntu 12.04 LTS上编译this example时遇到问题:
#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更好地使用我需要的库查找,链接和编译,所以使用this example我试图编写自己的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
如何修复这些错误?或者有更简单的方法来解决问题吗?
答案 0 :(得分:2)
我知道这是一个&#34;小&#34;晚了。但如果其他人遇到这个问题。这就是我做的。
我在我的电脑中复制了这个文件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)
所以我文件的前三行是:
cmake_minimum_required (VERSION 2.6)
project (test)
set(CMAKE_MODULE_PATH /home/user/Libs/cmake)
然后我运行cmake并制作,我没有错误。
答案 1 :(得分:0)
我强烈建议您将Qt Creator用于该特定教程。至少,我是这样做的。将IDE用于这些事情总是更好。我记得我必须重写CMakeLists文件的某些部分才能正确地构建到我的环境中(例如,我不想使用AntTweakBar)。
该教程提供的Qt Creator说明非常好,它们应该适合您。
另外,请记住安装您正在使用的教程中提到的每个软件包,包括CMake。如果我记得很清楚,他们应该工作得很好:)。