c++ - Compiling GLFW with Visual Studio 2012 -


the issue

as apparently many people (including here on stackoverflow), have run trouble compiling, , linking, c++ opengl code glfw library on visual studio (i using v11.0 aka 2012 ultimate).

here error list:

error   1   error lnk2019: unresolved external symbol __imp__glfwinit referenced in function _main  c:\users\dennis\myopengl\opengl1\opengl1\main.obj   opengl1 error   2   error lnk2019: unresolved external symbol __imp__glfwterminate referenced in function _main c:\users\dennis\myopengl\opengl1\opengl1\main.obj   opengl1 error   3   error lnk2019: unresolved external symbol __imp__glfwcreatewindow referenced in function _main  c:\users\dennis\myopengl\opengl1\opengl1\main.obj   opengl1 error   4   error lnk2019: unresolved external symbol __imp__glfwwindowshouldclose referenced in function _main c:\users\dennis\myopengl\opengl1\opengl1\main.obj   opengl1 error   5   error lnk2019: unresolved external symbol __imp__glfwpollevents referenced in function _main    c:\users\dennis\myopengl\opengl1\opengl1\main.obj   opengl1 error   6   error lnk2019: unresolved external symbol __imp__glfwmakecontextcurrent referenced in function _main    c:\users\dennis\myopengl\opengl1\opengl1\main.obj   opengl1 error   7   error lnk2019: unresolved external symbol __imp__glfwswapbuffers referenced in function _main   c:\users\dennis\myopengl\opengl1\opengl1\main.obj   opengl1 

here main.cpp file (containing code , workaround found):

#include <gl/glfw3.h>  //the workaround: #pragma comment(lib, "glfw3.lib") #pragma comment(lib, "opengl32.lib") #pragma comment(lib, "glu32.lib") //end workaround  int main(void) {     glfwwindow* window;      /* initialize library */     if (!glfwinit())         return -1;      /* create windowed mode window , opengl context */     window = glfwcreatewindow(640, 480, "hello world", null, null);     if (!window)     {         glfwterminate();         return -1;     }      /* make window's context current */     glfwmakecontextcurrent(window);      /* loop until user closes window */     while (!glfwwindowshouldclose(window))     {         /* render here */          /* swap front , buffers */         glfwswapbuffers(window);          /* poll , process events */         glfwpollevents();     }      glfwterminate();     return 0; } 

finally project .xml:

<?xml version="1.0" encoding="utf-8"?> <project defaulttargets="build" toolsversion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">   <itemgroup label="projectconfigurations">     <projectconfiguration include="debug|win32">       <configuration>debug</configuration>       <platform>win32</platform>     </projectconfiguration>     <projectconfiguration include="release|win32">       <configuration>release</configuration>       <platform>win32</platform>     </projectconfiguration>   </itemgroup>   <propertygroup label="globals">     <projectguid>{d8015b21-acee-4f49-b2e3-42d93127981a}</projectguid>     <keyword>win32proj</keyword>     <rootnamespace>opengl1</rootnamespace>   </propertygroup>   <import project="$(vctargetspath)\microsoft.cpp.default.props" />   <propertygroup condition="'$(configuration)|$(platform)'=='debug|win32'" label="configuration">     <configurationtype>application</configurationtype>     <usedebuglibraries>true</usedebuglibraries>     <platformtoolset>v110</platformtoolset>     <characterset>unicode</characterset>   </propertygroup>   <propertygroup condition="'$(configuration)|$(platform)'=='release|win32'" label="configuration">     <configurationtype>application</configurationtype>     <usedebuglibraries>false</usedebuglibraries>     <platformtoolset>v110</platformtoolset>     <wholeprogramoptimization>true</wholeprogramoptimization>     <characterset>unicode</characterset>   </propertygroup>   <import project="$(vctargetspath)\microsoft.cpp.props" />   <importgroup label="extensionsettings">   </importgroup>   <importgroup label="propertysheets" condition="'$(configuration)|$(platform)'=='debug|win32'">     <import project="$(userrootdir)\microsoft.cpp.$(platform).user.props" condition="exists('$(userrootdir)\microsoft.cpp.$(platform).user.props')" label="localappdataplatform" />   </importgroup>   <importgroup label="propertysheets" condition="'$(configuration)|$(platform)'=='release|win32'">     <import project="$(userrootdir)\microsoft.cpp.$(platform).user.props" condition="exists('$(userrootdir)\microsoft.cpp.$(platform).user.props')" label="localappdataplatform" />   </importgroup>   <propertygroup label="usermacros" />   <propertygroup condition="'$(configuration)|$(platform)'=='debug|win32'">     <linkincremental>true</linkincremental>   </propertygroup>   <propertygroup condition="'$(configuration)|$(platform)'=='release|win32'">     <linkincremental>false</linkincremental>   </propertygroup>   <itemdefinitiongroup condition="'$(configuration)|$(platform)'=='debug|win32'">     <clcompile>       <precompiledheader>       </precompiledheader>       <warninglevel>level3</warninglevel>       <optimization>disabled</optimization>       <preprocessordefinitions>win32;_debug;_console;%(preprocessordefinitions)</preprocessordefinitions>       <additionalincludedirectories>c:\users\dennis\programming\libraries\include;%(additionalincludedirectories)</additionalincludedirectories>     </clcompile>     <link>       <subsystem>console</subsystem>       <generatedebuginformation>true</generatedebuginformation>       <additionallibrarydirectories>c:\users\dennis\programming\libraries\lib;%(additionallibrarydirectories)</additionallibrarydirectories>     </link>   </itemdefinitiongroup>   <itemdefinitiongroup condition="'$(configuration)|$(platform)'=='release|win32'">     <clcompile>       <warninglevel>level3</warninglevel>       <precompiledheader>       </precompiledheader>       <optimization>maxspeed</optimization>       <functionlevellinking>true</functionlevellinking>       <intrinsicfunctions>true</intrinsicfunctions>       <preprocessordefinitions>win32;ndebug;_console;%(preprocessordefinitions)</preprocessordefinitions>       <additionalincludedirectories>c:\users\dennis\programming\libraries\include;%(additionalincludedirectories)</additionalincludedirectories>     </clcompile>     <link>       <subsystem>console</subsystem>       <generatedebuginformation>true</generatedebuginformation>       <enablecomdatfolding>true</enablecomdatfolding>       <optimizereferences>true</optimizereferences>       <additionallibrarydirectories>c:\users\dennis\programming\libraries\lib;%(additionallibrarydirectories)</additionallibrarydirectories>     </link>   </itemdefinitiongroup>   <itemgroup>     <clcompile include="main.cpp" />   </itemgroup>   <import project="$(vctargetspath)\microsoft.cpp.targets" />   <importgroup label="extensiontargets">   </importgroup> </project> 

the workaround

now did find rather strange workaround in answer this stackoverflow question (credits vircung):

make sure have glfw.dll in folder .exe file.  if won't help, add library glu32.lib.  use add libraries in code adding before main function. see wich libraries have linked without digging through options , menus.  #pragma comment(lib, "glfw.lib") #pragma comment(lib, "opengl32.lib") #pragma comment(lib, "glu32.lib") 

although use #pragma comment(lib, "glfw3.lib") since using glfw ver. 3. anyway, line magically fixes no errors. question is: why? how come have force pre-proccessor (and find) .lib

is there can change project settings or code not have use workaround?

as yngum says in comments, has nothing preprocessor, 1 way of linking libraries project.

the other way (providing have paths set properly) simple. open project settings going project > (your project name) properties or right click on project in solution explorer , select properties. next go linker > input , add libraries list of additional dependencies. might want change dropdown in upper top left all configurations both debug , release builds.

enter image description here


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -