2

This is driving me mad, I want to statically link to GLFW.lib, following section 4.2.1. of the readme.html file provided I have added glfw.lib and opengl32.lib to the additional dependancies section of the linker on VS.

I've also added the dir including glfw.lib to the additional library directories section under linker > general.

And of course I have included the glfw.h file in my project, yet I'm still getting...

Error   1   error LNK2019: unresolved external symbol _glfwInit referenced in function _main    C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Spark\main.obj   Spark
Error   2   error LNK2019: unresolved external symbol _glfwTerminate referenced in function _main   C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Spark\main.obj   Spark
Error   3   error LNK2019: unresolved external symbol _glfwOpenWindow referenced in function _main  C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Spark\main.obj   Spark
Error   4   error LNK2019: unresolved external symbol _glfwSwapBuffers referenced in function _main C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Spark\main.obj   Spark
Error   5   error LNK2019: unresolved external symbol _glfwGetWindowParam referenced in function _main  C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Spark\main.obj   Spark
Error   6   error LNK2019: unresolved external symbol _glfwGetKey referenced in function _main  C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Spark\main.obj   Spark
Error   7   error LNK1120: 6 unresolved externals   C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Debug\Spark.exe  1   1   Spark

With the following (example) code...

#include <glfw.h>
#include <stdlib.h>

int main( void )
{
    int running = GL_TRUE;

    // Initialize GLFW
    if( !glfwInit() )
    {
        exit( EXIT_FAILURE );
    }

    // Open an OpenGL window
    if( !glfwOpenWindow( 300,300, 0,0,0,0,0,0, GLFW_WINDOW ) )
    {
        glfwTerminate();
        exit( EXIT_FAILURE );
    }

    // Main loop
    while( running )
    {
        // OpenGL rendering goes here...
        glClear( GL_COLOR_BUFFER_BIT );
        // Swap front and back rendering buffers
        glfwSwapBuffers();
        // Check if ESC key was pressed or window was closed
        running = !glfwGetKey( GLFW_KEY_ESC ) &&
        glfwGetWindowParam( GLFW_OPENED );
    }

    // Close window and terminate GLFW
    glfwTerminate();

    // Exit program
    exit( EXIT_SUCCESS );
}

What am I doing wrong?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Cody Smith
  • 2,732
  • 3
  • 31
  • 43
  • I totally agree, link/compilation errors are one of the main reasons I like Java so much more than C++. Compilation in C++ sucks! – Name Dec 15 '12 at 04:40
  • 1
    Try adding `#pragma comment(lib, )` as the first line of the program. Replace `` with the actual file path, of course. This will at least ensure it is properly linked. – kevintodisco Dec 15 '12 at 05:01

2 Answers2

3

Make sure you have glfw.dll in folder with your .exe file. If this wont help, add another library glu32.lib.

I use to add libraries in code by adding this before main function. With this you see wich libraries you have linek without diging through options and menus.

#pragma comment(lib, "GLFW.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
0

Perhaps the reason is because you are linking to these libraries in only one build mode, say, release.

Second possible reason: (Correct me if I am wrong, as I am not 100% sure of this). The LIB files might have been built in different compiler. For example, the LIB was compiled in MinGW, and you are linking to it with the MSVC++ compiler.

Third possible reason: Consider what version of GLFW you are using (As in 32 bit, 64 bit).

Name
  • 2,037
  • 3
  • 19
  • 28
  • It mentions MinGW and MSYS. let me guess, that means I have to build this son of a bitch first? – Cody Smith Dec 15 '12 at 04:55
  • @CodySmith What do you mean by "it mentions MinGW and MSYS"? – kevintodisco Dec 15 '12 at 05:02
  • http://www.glfw.org/release-2.7.7.html#compiling It ships with binaries or source. I was trying to get the binaries to work, but if you want to compile the source it mentioned needing MinGW. – Cody Smith Dec 15 '12 at 05:10
  • @CodySmith Ah, ok. Note that VS 2008 and 2010 are also supported though, so it is not the case that you have to manually compile. I have succeeded in compiling and linking GLFW in the past, so it's most likely an error in your project settings that you're overlooking. – kevintodisco Dec 15 '12 at 05:16
  • Could you please, please help me figure this out? I honestly barely know enough VS to navigate the IDE. I'll even make it worth your time if I have to. Skype: codysmith105 Email: Smith@polynomic3D.com – Cody Smith Dec 15 '12 at 05:42
  • Hahahaha I win! x64 DLL's dont work on a x86 application (didn't realize my project was set to x86 in VS). – Cody Smith Dec 15 '12 at 05:55