C++ Eclipse CDT+;MinGW&x2B;GLEW,键入对“LoadShaders(char const*,char const*)';

C++ Eclipse CDT+;MinGW&x2B;GLEW,键入对“LoadShaders(char const*,char const*)';,c++,eclipse,opengl,glew,C++,Eclipse,Opengl,Glew,已仅为加载着色器获取一个错误 #include <stdio.h> #include <stdlib.h> #define GLEW_STATIC #include <GL/glew.h> #include <glfw3.h> GLFWwindow* window; #include <glm/glm.hpp> using namespace glm; #include <common/shader.hpp> in

已仅为
加载着色器
获取一个错误

#include <stdio.h>
#include <stdlib.h>

#define GLEW_STATIC
#include <GL/glew.h>

#include <glfw3.h>
GLFWwindow* window;

#include <glm/glm.hpp>
using namespace glm;

#include <common/shader.hpp>

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

    glfwWindowHint(GLFW_SAMPLES, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    // Open a window and create its OpenGL context
    window = glfwCreateWindow( 1024, 768, "Tutorial 02 - Red triangle", 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 for core profile
    if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEW\n");
        return -1;
    }

    // Ensure we can capture the escape key being pressed below
    glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

    // Dark blue background
    glClearColor(0.0f, 0.0f, 0.4f, 0.0f);

    GLuint VertexArrayID;
    glGenVertexArrays(1, &VertexArrayID);
    glBindVertexArray(VertexArrayID);

    // Create and compile our GLSL program from the shaders
    GLuint programID = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" );


    static const GLfloat g_vertex_buffer_data[] = {
        -1.0f, -1.0f, 0.0f,
         1.0f, -1.0f, 0.0f,
         0.0f,  1.0f, 0.0f,
    };

    GLuint vertexbuffer;
    glGenBuffers(1, &vertexbuffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);

    do{

        // Clear the screen
        glClear( GL_COLOR_BUFFER_BIT );

        // Use our shader
        glUseProgram(programID);

        // 1rst attribute buffer : vertices
        glEnableVertexAttribArray(0);
        glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
        glVertexAttribPointer(
            0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
            3,                  // size
            GL_FLOAT,           // type
            GL_FALSE,           // normalized?
            0,                  // stride
            (void*)0            // array buffer offset
        );

        // Draw the triangle !
        glDrawArrays(GL_TRIANGLES, 0, 3); // 3 indices starting at 0 -> 1 triangle

        glDisableVertexAttribArray(0);

        // 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 );

    // Cleanup VBO
    glDeleteBuffers(1, &vertexbuffer);
    glDeleteVertexArrays(1, &VertexArrayID);
    glDeleteProgram(programID);

    // Close OpenGL window and terminate GLFW
    glfwTerminate();

    return 0;
}
控制台中的编译器字符串:

g++ -o Opengl33.exe "src\\Opengl33.o" -lglew32s -lgdi32 -lopengl32 -lglfw3dll 
-DGLEW_STATIC
不要帮我)


我试图用谷歌搜索这个问题,但没有找到解决办法。

在不同的文件中实现方法/类时,必须将每个方法/类编译为对象文件,然后将它们链接在一起。虽然LoadShader是在shader.o中定义的,但这里只链接Opengl33.o。尝试将链接器行更改为:

g++ -o Opengl33.exe "src\\Opengl33.o" "common\\shader.o" -lglew32s -lgdi32 -lopengl32 -lglfw3dll 

尽管如此,我想知道为什么这是必要的,因为您使用的是eclipse。

我在这里没有看到LoadShader的定义,如果它是在common/shader.hpp中定义的,那么请也发布这个文件。#ifndef shader_hpp#define shader_hpp GLuint LoadShader(const char*vertext_file_path,const char*fragment_file_path)#endif-格式都是shader.hppsorry,不了解如何在注释中使用[code]如果您知道,请告诉我如何在Eclipse中创建此项-添加到链接器字符串“common\\shader.o”(common\\shader.hpp位于MinGW的“includes”中)。对不起,我是noob,刚开始编程。至少在我的eclipse中,这是对项目中包含的所有源文件自动完成的。shader.cpp文件是否已编译?对不起,在哪里可以看到已编译的shader.cpp?我必须搜索“shader.o”?请,再次为我愚蠢的问题感到抱歉…请查看控制台(您已经从那里复制了链接器行)。每个*.cpp文件都应该有一行g++-c..行。请参见链接器字符串中的“shader.cpp”:信息:内部生成器用于构建g++-O0-g3-Wall-c-fmessage length=0-o“src\\opengl33.o”“\\src\\opengl33.cpp“g++-o opengl33.exe”src\\opengl33.o-lglew32-lopengl32-lglfw3dll src\opengl33.o:In function
main:C:\workspace\opengl33\Debug/。/src/opengl33.cpp:61:LoadShaders(char const*,char const*)的未定义引用可能是,我必须将文件夹“common”移动到“src”?(使用opengl33.cpp放置)?现在“common/shader.cpp”位于“MinGW/includes”中
g++ -o Opengl33.exe "src\\Opengl33.o" "common\\shader.o" -lglew32s -lgdi32 -lopengl32 -lglfw3dll