【问题标题】:What does "Warning: corrupt .drectve at end of def file" mean? [duplicate]“警告:def 文件末尾损坏的 .drectve”是什么意思? [复制]
【发布时间】:2014-09-13 20:23:32
【问题描述】:

在这个环境下,我编译了一个c++/openGL的例子,贴在网上:

  1. Windows 7
  2. 代码::Blocks v 13.12
  3. MinGW 构建于 2013 年 10 月(不确定版本)
  4. mingw32-g++ v 4.8.1

来自codeincodeblock.com的代码:

#define GLEW_STATIC
// third-party libraries
#include <windows.h>
#include <GL/glew.h>
#include <GL/glfw.h>
#include <glm/glm.hpp>

#include <cassert>
#include <iostream>
#include <stdexcept>


GLuint gVAO = 0;
GLuint gVBO = 0;
GLuint programId;
const glm::vec2 SCREEN_SIZE(800, 600);

static void LoadTriangle() {
    // make and bind the VAO
    glGenVertexArrays(1, &gVAO);
    glBindVertexArray(gVAO);

    // make and bind the VBO
    glGenBuffers(1, &gVBO);
    glBindBuffer(GL_ARRAY_BUFFER, gVBO);

    // Put the three triangle verticies into the VBO
    GLfloat vertexData[] = {
        //  X     Y     Z
         0.0f, 0.8f, 0.0f,
        -0.8f,-0.8f, 0.0f,
         0.8f,-0.8f, 0.0f,
    };
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);

    // connect the xyz to the "vert" attribute of the vertex shader
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);

    // unbind the VBO and VAO
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindVertexArray(0);
}

// draws a single frame
static void Render() {
    // clear everything
    glClearColor(0, 0, 0, 1); // black
    glClear(GL_COLOR_BUFFER_BIT);



    // bind the VAO (the triangle)
    glBindVertexArray(gVAO);

    // draw the VAO
    glDrawArrays(GL_TRIANGLES, 0, 3);

    // unbind the VAO
    glBindVertexArray(0);

    // swap the display buffers (displays what was just drawn)
    glfwSwapBuffers();
}

// the program starts here
void AppMain() {
    // initialise GLFW
    if(!glfwInit())
        throw std::runtime_error("glfwInit failed");

    // open a window with GLFW
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
    glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE);
    if(!glfwOpenWindow((int)SCREEN_SIZE.x, (int)SCREEN_SIZE.y, 8, 8, 8, 8, 0, 0, GLFW_WINDOW))
        throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 3.2?");

    // initialise GLEW
    glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/
    if(glewInit() != GLEW_OK)
        throw std::runtime_error("glewInit failed");

    // print out some info about the graphics drivers
    std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
    std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
    std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
    std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;

    // make sure OpenGL version 3.2 API is available
    if(!GLEW_VERSION_3_2)
        throw std::runtime_error("OpenGL 3.2 API is not available.");

    // create buffer and fill it with the points of the triangle
    LoadTriangle();

    // run while the window is open
    while(glfwGetWindowParam(GLFW_OPENED)){
        // draw one frame
        Render();
    }

    // clean up and exit
    glfwTerminate();
}


int main(int argc, char *argv[]) {
    try {
        AppMain();
    } catch (const std::exception& e){
        std::cerr << "ERROR: " << e.what() << std::endl;
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}

我为使用 glfw3 制作的修改版本:

#define GLEW_STATIC
// third-party libraries
#include <windows.h>
#include <GL/glew.h>
#include <GL/glfw3.h>  // --- changed
#include <glm/glm.hpp>

#include <cassert>
#include <iostream>
#include <stdexcept>


GLuint gVAO = 0;
GLuint gVBO = 0;
GLuint programId;
const glm::vec2 SCREEN_SIZE(800, 600);
GLFWwindow *window;  // --- added

static void LoadTriangle() {
    // make and bind the VAO
    glGenVertexArrays(1, &gVAO);
    glBindVertexArray(gVAO);

    // make and bind the VBO
    glGenBuffers(1, &gVBO);
    glBindBuffer(GL_ARRAY_BUFFER, gVBO);

    // Put the three triangle verticies into the VBO
    GLfloat vertexData[] = {
        //  X     Y     Z
         0.0f, 0.8f, 0.0f,
        -0.8f,-0.8f, 0.0f,
         0.8f,-0.8f, 0.0f,
    };
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);

    // connect the xyz to the "vert" attribute of the vertex shader
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);

    // unbind the VBO and VAO
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindVertexArray(0);
}

// draws a single frame
static void Render(GLFWwindow *win) {  // --- changed
    // clear everything
    glClearColor(0, 0, 0, 1); // black
    glClear(GL_COLOR_BUFFER_BIT);



    // bind the VAO (the triangle)
    glBindVertexArray(gVAO);

    // draw the VAO
    glDrawArrays(GL_TRIANGLES, 0, 3);

    // unbind the VAO
    glBindVertexArray(0);

    // swap the display buffers (displays what was just drawn)
    glfwSwapBuffers(win);  // --- changed
}

// the program starts here
void AppMain() {
    // initialise GLFW
    if(!glfwInit())
        throw std::runtime_error("glfwInit failed");

    // open a window with GLFW
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);  // --- changed
    glfwWindowHint(GLFW_VERSION_MAJOR, 3);  // --- changed
    glfwWindowHint(GLFW_VERSION_MINOR, 2);  // --- changed
    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);  // --- changed

    window = glfwCreateWindow((int)SCREEN_SIZE.x, (int)SCREEN_SIZE.y,"Test window",0,0);  // --- changed

    if(window == NULL)
        throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 3.2?");

    // initialise GLEWuj
    glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/
    if(glewInit() != GLEW_OK)
        throw std::runtime_error("glewInit failed");

    // print out some info about the graphics drivers
    std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
    std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
    std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
    std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;

    // make sure OpenGL version 3.2 API is available
    if(!GLEW_VERSION_3_2)
        throw std::runtime_error("OpenGL 3.2 API is not available.");

    // create buffer and fill it with the points of the triangle
    LoadTriangle();

    // run while the window is open
    while(!glfwWindowShouldClose(window)){  // --- changed
        // draw one frame
        Render(window);  // --- changed
    }

    // clean up and exit
    glfwTerminate();
}


int main(int argc, char *argv[]) {
    try {
        AppMain();
    } catch (const std::exception& e){
        std::cerr << "ERROR: " << e.what() << std::endl;
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}

我将 -mwindows 添加到链接器选项中,并按照 Dinesh 在他的 Setup Modern OpenGL page 上的说明设置我的 openGL 环境。

请注意,Dinesh 使用较早的 glfw 构建,因此提示我进行更改以编译和执行代码。

无论如何,构建会产生以下输出:

=== Build: Debug in OpenGLTest (compiler: GNU GCC Compiler) ===
Warning: corrupt .drectve at end of def file
=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 5 second(s)) ===
=== Run: Debug in OpenGLTest (compiler: GNU GCC Compiler) ===

所以我的问题是:警告是什么意思,我应该关注什么?

【问题讨论】:

    标签: c++ opengl compiler-warnings mingw32


    【解决方案1】:

    当我遇到这个问题时,是因为我正在链接不兼容的 MSVC 库。 keltar 的评论帮助我解决了这个问题。

    SDL 2.0: linking error

    【讨论】:

    • 谢谢!我看着它并在我所拥有的东西上做了一些工作,但已经一个月了,从那以后我睡了很多次,我忘记了我做了哪些改变来尝试让它发挥作用。图。但是,下次我尝试时,我会从头开始并让它发挥作用。
    猜你喜欢
    • 2014-09-29
    • 1970-01-01
    • 2011-12-31
    • 2015-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-02
    相关资源
    最近更新 更多