How to build GLFW library from source in VS2012/Win32

Reading the very good book OpenGL 4 Shading Language Cookbook by David Wolff (as an opengl 1.x developer, I found the learn-by-example very fast to update my knowledge to OpenGL 4.3, and he also skips all well-know openGL basic stuff) I started adopting GLFW in my 3d graphic related framework (more precisely the glfw library).

I’ve found some issues linking the Library in my VS2012 projects (not so complicated, however, on the linux toolchains and the installation guidelines found here is very straightforward) so I will keep log of how to solve them in this post.

At first I’ve tried the pre-build library, but I stumble with a runtime error (heap error) during the call to glfwInit, and so I decide to dig more inside the library. First step: build from source following the building tutorial.

Building the Library

Using the library in a Win32 application, I’ve to change the library VS2012 projects settings  to correctly build the library (git + CMake to generate the VS2012 solution) with the ABI I need:

  1. The VS2012 solution file have many sub-projects, one of them is glfw, the library builder. I would like to use the static library version (.lib file, no .dll dependencies)
  2. select glfw, then Properties/Librarian/Target Machine, set to MachineX86. This step needed to avoid many linking errors with the API functions, like “_glfwInit referenced in function _main”
    Snap 2014-06-06 at 12.19.49
  3. Build / Configuration Manager, change for all configurations the “Active Solution Platform” to Win32. This step is needed to avoid “fatal error LNK1112: module machine type ‘X86’ conflicts with target machine type ‘AMD64′” error.
    Snap 2014-06-06 at 12.28.41
  4. I batch-build all 4 configuration for the project flgw (Release / Debug / MinSizeRel / RelWithDebInfo). Please check if the configuration is Win32, not x64. The output will be 4 directories, each of them containing the relative static compiled version of the library. Copy the output directory wherever you want or leave them there.Snap 2014-06-06 at 12.20.06
  5. Open the Win32 project where you want to use the GLFW to be used, add the link to the glfw3.lib file of your choice in the project settings or in a @pragma comment (lib,”dir-to-file/glfw3.lib) preprocessor macro and build the project.

That’s all.

GLFW compiled

 

Pubblicato da adec

I'm a computer science engineer, Rome, Italy.

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.