Linking Problems
-
This might be a simple problem, but I'm unable to fix it or find an appropriate answer. I startet with Qt and tried a simple example usind glew and glfw libraries, but I get "undefined reference" errors for every glfw command... I know that I have to link the libraries after the sources that need them, I thought I had done so, but this obviouly seems not to be the case.
I have the glfw-files "glfw3.h", "glfw3.dll", "glfw3dll.a" and "libglfw3.a" in C:/LIBS/glfw
This is the code of my .pro:
TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += main.cpp include(deployment.pri) qtcAddDeployment() LIBS += -LC:/LIBS/glew/ -lglew32 -LC:/LIBS/glfw/ -lglfw3 INCLUDEPATH += C:/LIBS/glew C:/LIBS/glfw DEPENDPATH += C:/LIBS/glew C:/LIBS/glfw
This is my main.cpp:
#include <stdio.h> #include <stdlib.h> #include <glew.h> #include <C:/LIBS/glfw/glfw3.h> GLFWwindow* window; #include <C:/LIBS/glm/glm.hpp> using namespace glm; int main( void ) { // Initialise GLFW if( !glfwInit() ) { fprintf( stderr, "Failed to initialize GLFW\n" ); return -1; } glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_RESIZABLE,GL_FALSE); 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, "Playground", 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 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); do{ // Draw nothing, see you in tutorial 2 ! // 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 ); // Close OpenGL window and terminate GLFW glfwTerminate(); return 0; }
Thanks for help
-
Hi,
Are you using the right compiler/linker? Looking at your files I'd say it's MinGW so maybe check if you're not compiling with MSVC whose linker would not recognize the .a files. Also you shouldn't need to use the absolute path in the #include directive in your main.cpp; just
#include <glfw3.h>
should work (but I very much doubt that's your problem). -
Hi,
I have Qt for Windows with the included MinGW. In the compiler setting there are only the included MinGW versions listed.
Changing the include path doesn't get it to work.
-
Ok, is the library 32bit? Because if it's 64bit it will not work since Qt's included MinGW is 32bit.
And have you tried linking to glfw3dll? -
It's the 32 bit version.
When I link with glfw3dll, I also have to define the GLFW header option macro GLFW_DLL and I don't know how this is done correctly. Do I have to write a #define command before the #include<glfw3.h>, or do I have to write a DEFINES command?
I have added -lopengl32 -lglu32 to -lglfw3 then I get refference errors in "win32_window.c" and "wgl_context.c", so I guess I have to link to other libraries as well, but I don't know which ones...
The doc of glfw tells that using the dll one would not need to link against any of its dependencies.
-
@StephanP Link with gdi32 too (It's in the doc). Do you use glu32? Because if not, you don't need to link with it.
-
This is it! Thanks!