Skip to content

Instantly share code, notes, and snippets.

@z3t0
Created May 18, 2015 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z3t0/e0ba524f2c0df124f5e8 to your computer and use it in GitHub Desktop.
Save z3t0/e0ba524f2c0df124f5e8 to your computer and use it in GitHub Desktop.
Error from trying to build OpenGL Application
λ make
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Using Win32 for window creation
-- Using WGL for context creation
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Rafi Khan/Documents/voxy
[ 22%] Built target glfw
Linking CXX executable bin/voxy.exe
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0xb): undefined reference to `_imp____glewCreateShader'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x21): undefined reference to `_imp____glewCreateShader'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x256): undefined reference to `_imp____glewShaderSource'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x27f): undefined reference to `_imp____glewCompileShader'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x291): undefined reference to `_imp____glewGetShaderiv'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x2b2): undefined reference to `_imp____glewGetShaderiv'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x311): undefined reference to `_imp____glewGetShaderInfoLog'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x398): undefined reference to `_imp____glewShaderSource'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x3c1): undefined reference to `_imp____glewCompileShader'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x3d3): undefined reference to `_imp____glewGetShaderiv'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x3f4): undefined reference to `_imp____glewGetShaderiv'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x453): undefined reference to `_imp____glewGetShaderInfoLog'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x4c6): undefined reference to `_imp____glewCreateProgram'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x4d2): undefined reference to `_imp____glewAttachShader'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x4eb): undefined reference to `_imp____glewAttachShader'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x504): undefined reference to `_imp____glewLinkProgram'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x516): undefined reference to `_imp____glewGetProgramiv'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x537): undefined reference to `_imp____glewGetProgramiv'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x596): undefined reference to `_imp____glewGetProgramInfoLog'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x5fd): undefined reference to `_imp____glewDeleteShader'
CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj):shaderLoader.cpp:(.text+0x60f): undefined reference to `_imp____glewDeleteShader'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: CMakeFiles/voxy.dir/objects.a(shaderLoader.cpp.obj): bad reloc address 0x1b in secti
on `.text$printf[_printf]'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [bin/voxy.exe] Error 1
make[1]: *** [CMakeFiles/voxy.dir/all] Error 2
make: *** [all] Error 2
/* Copyright 2015 Rafi Khan */
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
#include "util/shaderLoader.hpp"
#define WIDTH 800
#define HEIGHT 600
void key_callback(GLFWwindow* window, int key, int scancode, int action,
int mode) {
// When a user presses the escape key, we set the WindowShouldClose property
// to true,
// closing the application
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
}
int main() {
// GLFW
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
GLFWwindow* window =
glfwCreateWindow(WIDTH, HEIGHT, "Voxy", nullptr, nullptr);
glfwMakeContextCurrent(window);
if (window == NULL) {
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
} else {
std::cout << "Window created" << std::endl;
}
// GLEW
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK) {
std::cout << "Failed to initialize GLEW" << std::endl;
return -1;
}
// Init
glViewport(0, 0, WIDTH, HEIGHT);
GLfloat vertices[] = {-0.5f, -0.5f, 0.0f, 0.5f, -0.5f,
0.0f, 0.0f, 0.5f, 0.0f};
void key_callback(GLFWwindow * window, int key, int scancode, int action,
int mode);
static const GLfloat verts[] = {
-1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
};
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
// Load Shaders
GLuint program = LoadShaders("shader.vert", "shader.frag");
glUseProgram(program);
// std::string vertexShaderSource;
// GLuint vertexShader;
// vertexShader = glCreateShader(GL_VERTEX_SHADER);
// glShaderSource(vertexShader, 1, &vertexShaderSource, nullptr)
// Render Loop
while (!glfwWindowShouldClose(window)) {
glClearColor(0.0f, 0.0f, 0.3f, 0.7f);
glClear(GL_COLOR_BUFFER_BIT);
// Check and call events
glfwPollEvents();
// Render things here
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
// Swap the buffers
glfwSwapBuffers(window);
}
glfwTerminate();
}
#include <stdio.h>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
#include <stdlib.h>
#include <string.h>
#include <GL/glew.h>
#include "shaderLoader.hpp"
GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path){
// Create the shaders
GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
// Read the Vertex Shader code from the file
std::string VertexShaderCode;
std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
if(VertexShaderStream.is_open()){
std::string Line = "";
while(getline(VertexShaderStream, Line))
VertexShaderCode += "\n" + Line;
VertexShaderStream.close();
}else{
printf("Impossible to open %s. Are you in the right directory ? Don't forget to read the FAQ !\n", vertex_file_path);
getchar();
return 0;
}
// Read the Fragment Shader code from the file
std::string FragmentShaderCode;
std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
if(FragmentShaderStream.is_open()){
std::string Line = "";
while(getline(FragmentShaderStream, Line))
FragmentShaderCode += "\n" + Line;
FragmentShaderStream.close();
}
GLint Result = GL_FALSE;
int InfoLogLength;
// Compile Vertex Shader
printf("Compiling shader : %s\n", vertex_file_path);
char const * VertexSourcePointer = VertexShaderCode.c_str();
glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
glCompileShader(VertexShaderID);
// Check Vertex Shader
glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
if ( InfoLogLength > 0 ){
std::vector<char> VertexShaderErrorMessage(InfoLogLength+1);
glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
printf("%s\n", &VertexShaderErrorMessage[0]);
}
// Compile Fragment Shader
printf("Compiling shader : %s\n", fragment_file_path);
char const * FragmentSourcePointer = FragmentShaderCode.c_str();
glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
glCompileShader(FragmentShaderID);
// Check Fragment Shader
glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
if ( InfoLogLength > 0 ){
std::vector<char> FragmentShaderErrorMessage(InfoLogLength+1);
glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
printf("%s\n", &FragmentShaderErrorMessage[0]);
}
// Link the program
printf("Linking program\n");
GLuint ProgramID = glCreateProgram();
glAttachShader(ProgramID, VertexShaderID);
glAttachShader(ProgramID, FragmentShaderID);
glLinkProgram(ProgramID);
// Check the program
glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
if ( InfoLogLength > 0 ){
std::vector<char> ProgramErrorMessage(InfoLogLength+1);
glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
printf("%s\n", &ProgramErrorMessage[0]);
}
glDeleteShader(VertexShaderID);
glDeleteShader(FragmentShaderID);
return ProgramID;
}
#ifndef SHADERLOADER_HPP
#define SHADERLOADER_HPP
GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path);
#endif
@z3t0
Copy link
Author

z3t0 commented May 19, 2015

Fixed by using #define GLEW_STATIC on both .cpp files

@zzheng90
Copy link

Fixed by using #define GLEW_STATIC on both .cpp files
Excuse me, you mean that by adding a line '#define GLEW_STATIC ' in all '.ccp' files, we can resolve the problem?

@z3t0
Copy link
Author

z3t0 commented Mar 21, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment