PDA

View Full Version : Can't compile example from GLFW website (Undefined references to GLFW functions)



Marc Colomé
09-03-2014, 07:47 AM
Hello, i have dowloaded the Windows precompiled binaries and putted:

glfw3.dll on SysWOW64

In order of linked in CodeBlocks: libglfw3.a, libopengl32.a, libglu32.a, libgdi32.a on C:\\MinGW\lib

In C:\\MinGW\include\GL\ i have gl.h, glext.h, glfw3.h, glfw3native.h and glu.h

The code i attempt to compile is this:


#include <GL/glfw3.h>
#include <stdlib.h>
#include <stdio.h>
static void error_callback(int error, const char* description)
{
fputs(description, stderr);
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
}
int main(void)
{
GLFWwindow* window;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(EXIT_FAILURE);
window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
if (!window)
{
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, key_callback);
while (!glfwWindowShouldClose(window))
{
float ratio;
int width, height;
glfwGetFramebufferSize(window, &width, &height);
ratio = width / (float) height;
glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef((float) glfwGetTime() * 50.f, 0.f, 0.f, 1.f);
glBegin(GL_TRIANGLES);
glColor3f(1.f, 0.f, 0.f);
glVertex3f(-0.6f, -0.4f, 0.f);
glColor3f(0.f, 1.f, 0.f);
glVertex3f(0.6f, -0.4f, 0.f);
glColor3f(0.f, 0.f, 1.f);
glVertex3f(0.f, 0.6f, 0.f);
glEnd();
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
exit(EXIT_SUCCESS);
}




My pc is Win8.1 64bit and i'm getting this errors:

||=== Build: Debug in SIM (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `key_callback':|
C:\Users\Marc\Documents\C++\SIM\main.cpp|11|undefi ned reference to `glfwSetWindowShouldClose'|
obj\Debug\main.o||In function `main':|
C:\Users\Marc\Documents\C++\SIM\main.cpp|16|undefi ned reference to `glfwSetErrorCallback'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|17|undefi ned reference to `glfwInit'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|19|undefi ned reference to `glfwCreateWindow'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|22|undefi ned reference to `glfwTerminate'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|25|undefi ned reference to `glfwMakeContextCurrent'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|26|undefi ned reference to `glfwSetKeyCallback'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|31|undefi ned reference to `glfwGetFramebufferSize'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|40|undefi ned reference to `glfwGetTime'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|49|undefi ned reference to `glfwSwapBuffers'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|50|undefi ned reference to `glfwPollEvents'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|27|undefi ned reference to `glfwWindowShouldClose'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|52|undefi ned reference to `glfwDestroyWindow'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|53|undefi ned reference to `glfwTerminate'|
||=== Build failed: 14 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

I get errors at all glfw functions.

Whhat i do have messed up?

Agent D
09-03-2014, 08:46 AM
Hello, i have dowloaded the Windows precompiled binaries and putted:

glfw3.dll on SysWOW64

Don't ever do this! This isn't a Unix(R) system. The library goes into the same directory as the application binary.



In order of linked in CodeBlocks: libglfw3.a, libopengl32.a, libglu32.a, libgdi32.a on C:\\MinGW\lib

In C:\\MinGW\include\GL\ i have gl.h, glext.h, glfw3.h, glfw3native.h and glu.h

Did you copy the glfw libraries into the MinGW lib directory? Same thing as above. Put them in some directory that contains your programs dependencies (same for the headers).


||=== Build: Debug in SIM (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `key_callback':|
C:\Users\Marc\Documents\C++\SIM\main.cpp|11|undefi ned reference to `glfwSetWindowShouldClose'|
obj\Debug\main.o||In function `main':|
C:\Users\Marc\Documents\C++\SIM\main.cpp|16|undefi ned reference to `glfwSetErrorCallback'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|17|undefi ned reference to `glfwInit'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|19|undefi ned reference to `glfwCreateWindow'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|22|undefi ned reference to `glfwTerminate'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|25|undefi ned reference to `glfwMakeContextCurrent'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|26|undefi ned reference to `glfwSetKeyCallback'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|31|undefi ned reference to `glfwGetFramebufferSize'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|40|undefi ned reference to `glfwGetTime'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|49|undefi ned reference to `glfwSwapBuffers'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|50|undefi ned reference to `glfwPollEvents'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|27|undefi ned reference to `glfwWindowShouldClose'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|52|undefi ned reference to `glfwDestroyWindow'|
C:\Users\Marc\Documents\C++\SIM\main.cpp|53|undefi ned reference to `glfwTerminate'|
||=== Build failed: 14 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

I get errors at all glfw functions.

Whhat i do have messed up?
You oviously didn't link against GLFW. The linker flag "-lglfw" should be set. The IDE you use should have some menu where you can point it at the GLFW library directory and specify what libraries to link against.