3

I've written a simple program using glfw3 and I believe I've linked the applicable (static) libraries and included the header file correctly.

#include "Main.h"
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
using namespace std;

Main::Main() {
    if (glfwInit()) {
        GLFWwindow* window = glfwCreateWindow(640, 480, "Woo", NULL, NULL);

        glfwDestroyWindow(window);
    }
}

int main() {
    int val = 0;
    Main* test = new Main();
    return val;
}

Main::~Main() {
    // TODO Auto-generated destructor stub
}

Below is my command line output:

23:20:58 **** Incremental Build of configuration Debug for project Void ****
Info: Internal Builder is used for build
g++ -L../lib -static -o Void Main.o -lglfw3 -lgdi32 -lglew32 -lopengl32 
Main.o: In function `ZN4MainC2Ev':
G:\eclipse\CPP WorkSpace\Void\Debug/../Main.cpp:15: undefined reference to `glfwInit'
G:\eclipse\CPP WorkSpace\Void\Debug/../Main.cpp:16: undefined reference to `glfwCreateWindow'
G:\eclipse\CPP WorkSpace\Void\Debug/../Main.cpp:18: undefined reference to `glfwCreateWindow'
G:\eclipse\CPP WorkSpace\Void\Debug/../Main.cpp:20: undefined reference to `glfwDestroyWindow'
collect2.exe: error: ld returned 1 exit status

23:20:59 Build Finished (took 205ms)

I've been looking all over google and stackoverflow and I must be missing something. My libraries could be 32 bit and I'm trying to compile to 64 bit, though I'm not sure how to check this.
Also, you'll notice that I've included the glew header file. If I call functions included in that, they are defined and don't cause any problems. Any help at all is greatly appreciated.

UPDATE: After attempting to build with the 32 bit library for glfw (libglfw3.a), I got a new error. ../lib\libglfw3.a(init.c.obj):init.c:(.text+0x49): undefined reference to `__ms_vsnprintf'

2 Answers2

1

Hello subtlepseudonym,

The error : "../lib\libglfw3.a(init.c.obj):init.c:(.text+0x49): undefined reference to `__ms_vsnprintf'"

in my opinion is due to the fact that you are trying to build your code on Linux, but the glfw binaries you have are for windows platform.

I assume you are on linux/unix platform as I see compiler as g++.

"__ms_vsnprintf" is present in glfw libraries built for windows platform.

I tried building your code at my end with a little modification and by building, using "glew" and "glfw" locally, and it worked perfectly.

If you are still facing an issue I will also add those details.

Community
  • 1
  • 1
  • I'm on Windows 7 using mingw. I'll give the linux binaries a try and let you know what happens. Thank you for the reply. – subtlepseudonym Jul 21 '15 at 23:50
  • I've compiled GLFW using cmake and have included the glfw3.h file from it. The project still does not compile and lists methods from glfw3.h as being undefined (as shown in the compiler output above). – subtlepseudonym Jul 22 '15 at 00:26
  • I got it working by importing glfw3dll.a after renaming it to libglfw3dll.a. This seems like a hackish solution though. – subtlepseudonym Jul 22 '15 at 02:29
  • "subtlepseudonym" if its windows and mingw there are multiple threads on stackoverflow itself which I find similar I am listing them below – anupkholgade Jul 22 '15 at 04:30
  • 1) http://stackoverflow.com/questions/22623087/undefined-reference-errors-when-linking-glfw-with-mingw-gcc?rq=1 2) http://stackoverflow.com/questions/22008845/glfw-mingw-link-error?rq=1 3) Also here is one more from "codeincodeblock" http://www.codeincodeblock.com/2011/02/setup-glfw-project-in-codeblock.html. Hope this helps – anupkholgade Jul 22 '15 at 04:32
  • Turns out I'm compiling a 64 bit application and using a mix of 32 and 64 bit libraries. I got the code to build wihout errors, but upon running, I get the error code 0xc0000007b. Thanks for all the help. (The last link was the most useful). – subtlepseudonym Jul 23 '15 at 09:48
-1

I had similar problem:

GLFWwindow* window = glfwCreateWindow (640, 480, "just a random title", NULL, NULL);

linker error:

undefined reference to `_imp__glfwCreateWindow'

After trying numerous "solutions", the fix was to remove #define GLFW_DLL:

// #define GLFW_DLL
#include <GLFW/glfw3.h>
Louen
  • 3,617
  • 1
  • 29
  • 49
TQQ
  • 1