Handmade Network»Forums
5 posts
Issues linking with GLFW from command line
At the moment, I am trying to make a project using GLFW, but I am getting a LNK2019 error for all glfw function. Most tutorials I seen involves using visual studio or CMake to setup the project, but finding a tutorial using the command line is hard to come by. On the bottom of the GLFW site about manual compilation, I do not really understand how it want me to setup the build (I still relatively new to building from command line). I am using Casey's build has the baseline for my GLFW build. I tried using /LIBPATH to tell the linker where it can find the glfw3.lib library, but still have errors. I also tried to mimic how visual studio setup GLFW, but came up with nothing. I also thought that the LNK 4272 warning was the issue and tried putting /machine:x86 on the linker, but that gave me an another problem.

Is it possible to link to glfw3.lib from command line? If so, how?



Workstation machine: Surface Pro 4 x64
Compiler: cl.exe x64
GLFW Download: 32-bit Windows binaries


My build file:
1
2
3
4
5
pushd ..\..\build

cl -nologo -IW:\glplay\glplay\Dependencies\GLFW\include ..\glplay\code\main.cpp /link /LIBPATH:W:\glplay\glplay\Dependencies\GLFW\lib-vc2015 glfw3.lib opengl32.lib user32.lib gdi32.lib

popd


Error code:
1
2
3
4
5
6
7
8
main.obj : error LNK2019: unresolved external symbol glfwInit referenced in function main
main.obj : error LNK2019: unresolved external symbol glfwTerminate referenced in function main
main.obj : error LNK2019: unresolved external symbol glfwCreateWindow referenced in function main
main.obj : error LNK2019: unresolved external symbol glfwWindowShouldClose referenced in function main
main.obj : error LNK2019: unresolved external symbol glfwPollEvents referenced in function main
main.obj : error LNK2019: unresolved external symbol glfwMakeContextCurrent referenced in function main
main.obj : error LNK2019: unresolved external symbol glfwSwapBuffers referenced in function main
glfw3.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'

Mārtiņš Možeiko
2561 posts / 2 projects
Issues linking with GLFW from command line
warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'

This is compiler telling you that you are trying to link library which has 32-bit Intel x86 code with application that is compiled for 64-bit Intel x86_64 code. This is not supported. You are simply using wrong glfw library. Get the right one - for 64-bit builds.
5 posts
Issues linking with GLFW from command line
mmozeiko
Get the right one - for 64-bit builds.


Just tried using x64 glfw3.lib and got the same error code above.

However, I did switch the compilation from x64 to x86 on the x86 glfw3.lib and got a different set of error code. From that, I was able to add in the libraries I needed and got the glfw window to pop-up

Thanks for the help