带有CMAKE和GLEW GLFW3和GLM库的OpenGL
Opengl with cmake and glew glfw3 and glm libraries
我有一个问题,在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 GLFWn" );
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 GLEWn");
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
如何解决这些错误?还是有一种更简单的方法来解决问题?
我知道这是一个"小"。但是,如果其他人遇到了这个问题。这就是我所做的。
我复制了此文件https://github.com/groovounet/glm-deprecated/blob/master/master/master/util/findglm.cmake在我的计算机I.E/home/user/libs/libs/cmake/cmake/findglm.findglm.cmakem.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并做出,我没有错误。
我强烈建议您将QT创建者用于该特定教程。至少,我这样做了。将IDE用于这些事情总是最好的。我记得我必须重写cmakelists文件的某些部分才能正确地构建到我的环境中(例如,我不想使用anttweakbar)。
该教程提供的QT创建者说明真的很好,他们应该为您工作。
另外,请记住要安装您使用的该教程中提到的每个包装,包括CMAKE。如果我还记得很好,他们应该正常工作:)
相关文章:
- c++库的公共头文件中应该包含什么
- 序列化,没有库的整数,得到奇怪的结果
- 停止cmake target_link_libraries将插件中静态库的两个对象文件链接到静态库本身
- 针对遗留库的链接:来自预制makefile的-lgfortranbegin
- 将 OpenCV 与 CMAKE 中的项目一起构建为第三方库的正确方法
- Android Studio 中带有静态库的原生C++代码
- 如何在OpenSSL库的名称中添加后缀'd'?
- 在OSX上使用CMake将Adobe的XMP工具包构建为共享库的最简单方法是什么?
- 为什么提升图库的 read_graphviz() 函数会改变节点的索引
- 如何减慢从 BVH 文件读取的 opengl 动画?
- 在Visual Studio C++项目中包含源库的正确方法是什么?
- 在没有库的情况下初始化 OpenGL
- OpenGL库的实现
- 带有CMAKE和GLEW GLFW3和GLM库的OpenGL
- OpenGL Aux库的安装
- 带有SDL/加载库的现代OpenGL
- 我使用Microsoft Visual Studio 2013中的GLFW和GLEW库在OpenGL中编写了一个程序.我
- 用简单的opengl图像库(SOIL)加载一张图像(颜色空间:GRAY)
- 将wxwidgets opengl应用程序移植到不依赖库的应用程序
- 是否有一个方便的字体库为OpenGL-ES 2像glFont