Search code examples
c++g++eclipse-cdtglfw

Trouble Compiling C++ (with GLFW)


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'


Solution

  • 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.