所以我正在使用Clion并编写OpenGL教程。首先,我复制了一些基本代码以确保正确设置了cmake,但是在运行程序时它给了我以下错误:进程结束,退出代码为-1073741515(0xC0000135)。我知道此错误意味着它找不到dll文件,但我不知道该文件丢失了。
cmake_minimum_required(VERSION 3.10)
project(Tetformer)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
set(LIBR_ROOT "${PROJECT_SOURCE_DIR}/Library")
set(LIB_DIR "${LIBR_ROOT}/lib")
set(INC_DIR "${LIBR_ROOT}/include")
set(BIN_DIR "${LIBR_ROOT}/bin")
set(LIBS glfw3 glew32s glu32 opengl32)
link_directories(${LIB_DIR})
link_directories(${BIN_DIR})
set(SOURCE_FILES main.cpp Game.h Game.cpp Texture.h Texture.cpp Shader.h Shader.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${LIBS})
list(APPEND CMAKE_PREFIX_PATH ${INC_DIR})
# opengl
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIRS})
# glfw
find_package(glfw3 REQUIRED)
include_directories(${GLFW_INCLUDE_DIRS})
link_libraries(${GLFW_LIBRARY_DIRS})
# glew
find_package(GLEW REQUIRED)
if (GLEW_FOUND)
include_directories(${GLEW_INCLUDE_DIRS})
link_libraries(${GLEW_LIBRARIES})
endif()
# glad
add_library("glad" "${LIBR_ROOT}/src/glad.c")
target_include_directories("glad" PRIVATE "${LIBR_ROOT}/include")
target_include_directories(Tetformer PRIVATE "${LIBR_ROOT}/include")
target_link_libraries(Tetformer "glad" "${CMAKE_DL_LIBS}")
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void processInput(GLFWwindow *window);
// settings
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
int main()
{
// glfw: initialize and configure
// ------------------------------
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // uncomment this statement to fix compilation on OS X
#endif
// glfw window creation
// --------------------
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
// glad: load all OpenGL function pointers
// ---------------------------------------
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
// render loop
// -----------
while (!glfwWindowShouldClose(window))
{
// input
// -----
processInput(window);
// render
// ------
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// -------------------------------------------------------------------------------
glfwSwapBuffers(window);
glfwPollEvents();
}
// glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------
glfwTerminate();
return 0;
}
// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
// ---------------------------------------------------------------------------------------------------------
void processInput(GLFWwindow *window)
{
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
}
// glfw: whenever the window size changed (by OS or user resize) this callback function executes
// ---------------------------------------------------------------------------------------------
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
// make sure the viewport matches the new window dimensions; note that width and
// height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);
}
Directory of C:\Users\Greg\Desktop\Game\Tetformer
07/10/2018 05:32 PM <DIR> .
07/10/2018 05:32 PM <DIR> ..
07/09/2018 10:15 PM 1,431 .gitignore
07/13/2018 05:44 PM <DIR> .idea
07/10/2018 04:08 PM <DIR> cmake
07/10/2018 05:32 PM <DIR> cmake-build-debug
07/10/2018 05:32 PM 1,223 CMakeLists.txt
07/09/2018 10:15 PM 73 Game.cpp
07/10/2018 12:21 AM 339 Game.h
07/10/2018 02:17 AM <DIR> Library
07/10/2018 05:20 PM 2,965 main.cpp
07/09/2018 10:15 PM 4,068 Shader.cpp
07/09/2018 10:15 PM 1,185 Shader.h
07/09/2018 10:15 PM 1,023 Texture.cpp
07/09/2018 10:15 PM 335 Texture.h
Directory of C:\Users\Greg\Desktop\Game\Tetformer\Library
07/10/2018 02:17 AM <DIR> .
07/10/2018 02:17 AM <DIR> ..
07/09/2018 11:01 PM <DIR> bin
07/10/2018 02:17 AM <DIR> include
07/10/2018 05:01 PM <DIR> lib
07/10/2018 02:17 AM <DIR> src
Directory of C:\Users\Greg\Desktop\Game\Tetformer\Library\lib
07/10/2018 05:01 PM <DIR> .
07/10/2018 05:01 PM <DIR> ..
07/31/2017 07:42 AM 701,288 glew32.lib
07/31/2017 07:42 AM 2,584,968 glew32s.lib
08/18/2016 08:05 AM 279,234 glfw3.dll
07/10/2018 04:47 PM 317,784 libglad.a
08/18/2016 08:05 AM 150,452 libglfw3.a
08/18/2016 08:05 AM 65,788 libglfw3dll.a
Directory of C:\Users\Greg\Desktop\Game\Tetformer\Library\include
07/10/2018 02:17 AM <DIR> .
07/10/2018 02:17 AM <DIR> ..
07/31/2017 07:46 AM <DIR> GL
07/10/2018 02:17 AM <DIR> glad
08/18/2016 07:52 AM <DIR> GLFW
05/22/2018 04:35 AM <DIR> glm
07/10/2018 02:17 AM <DIR> KHR
Directory of C:\Users\Greg\Desktop\Game\Tetformer\Library\bin
07/09/2018 11:01 PM <DIR> .
07/09/2018 11:01 PM <DIR> ..
07/31/2017 07:42 AM 422,912 glew32.dll
07/31/2017 07:42 AM 539,648 glewinfo.exe
07/31/2017 07:42 AM 338,432 visualinfo.exe
Directory of C:\Users\Greg\Desktop\Game\Tetformer\Library\src
07/10/2018 02:17 AM <DIR> .
07/10/2018 02:17 AM <DIR> ..
07/10/2018 08:17 AM 144,929 glad.c
我假设问题出在cmake文件上,但我不能说出它丢失了什么。该项目已构建,并且具有所有适当的Find.cmake文件,但是当您单击运行时,它将返回退出代码。
任何帮助将不胜感激:)
答案 0 :(得分:0)
如果您的程序成功构建,并且在启动时抱怨缺少.dll文件,则必须将有问题的.dll文件复制到.exe所在的目录中。
Windows通常会告诉您缺少的.dll文件。
答案 1 :(得分:0)
好的,非常感谢user4581301提到Dependency Walker来帮助我。事实证明,该程序无法找到glew32.dll,因为它位于bin文件夹而不是lib文件夹中。谢谢你!