Search code examples
cglfwglad

Unable to compile GLFW and GLAD


I was trying to setup a project with GLFW and GLAD. The file structure is as following:

opengl
│   build.bat
│   main.c
│
├───bin
│
├───deps
│   └───lib-vc2022
│           glfw3.lib
│
└───include
    ├───glad
    │       glad.c
    │       glad.h
    │
    ├───GLFW
    │       glfw3.h
    │       glfw3native.h
    │
    └───KHR
            khrplatform.h

I have run vcvarsall.bat and set the compiler to be x64 so I have access to the msvc compiler. To compile the code I ran build.bat which contains: (I got the 64 bit Prebuilt Windows binary from the glfw website)

@echo off

if not exist bin mkdir bin

pushd bin

cl  /Zi /Od /I..\include  C:\Dev\opengl\include\glad\glad.c ..\main.c  /link /NODEFAULTLIB /LIBPATH:..\deps\lib-vc2022 glfw3.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib opengl32.lib
popd 

main.c contains the code required to open a window in glfw. The files I have included in main.c is as following:

#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <stdio.h>

I then ran build.bat and got the following errors:

glad.obj : error LNK2019: unresolved external symbol __stdio_common_vssca
nf referenced in function _vsscanf_s_l
glad.obj : error LNK2019: unresolved external symbol free referenced in f
unction free_exts
glad.obj : error LNK2019: unresolved external symbol malloc referenced in
 function get_exts
glad.obj : error LNK2019: unresolved external symbol memcpy referenced in
 function get_exts
glfw3.lib(input.obj) : error LNK2001: unresolved external symbol memcpy
glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol
memcpy
glad.obj : error LNK2019: unresolved external symbol strlen referenced in
 function get_exts
glad.obj : error LNK2019: unresolved external symbol strncmp referenced i
n function find_coreGL
glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol
 __GSHandlerCheck
glfw3.lib(wgl_context.obj) : error LNK2001: unresolved external symbol __
GSHandlerCheck
glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol __
GSHandlerCheck
glfw3.lib(osmesa_context.obj) : error LNK2001: unresolved external symbol
 __GSHandlerCheck
glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __GSHand
lerCheck
glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol __G
SHandlerCheck
glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol
__GSHandlerCheck
glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol _
_GSHandlerCheck
glad.obj : error LNK2001: unresolved external symbol __GSHandlerCheck
glfw3.lib(init.obj) : error LNK2001: unresolved external symbol __GSHandl
erCheck
glfw3.lib(window.obj) : error LNK2001: unresolved external symbol __GSHan
dlerCheck
glfw3.lib(context.obj) : error LNK2001: unresolved external symbol __GSHa
ndlerCheck
glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol
 __security_check_cookie
glfw3.lib(wgl_context.obj) : error LNK2001: unresolved external symbol __
security_check_cookie
glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol __
security_check_cookie
glfw3.lib(osmesa_context.obj) : error LNK2001: unresolved external symbol
 __security_check_cookie
glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __securi
ty_check_cookie
glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol __s
ecurity_check_cookie
glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol
__security_check_cookie
glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol _
_security_check_cookie
glad.obj : error LNK2001: unresolved external symbol __security_check_coo
kie
glfw3.lib(init.obj) : error LNK2001: unresolved external symbol __securit
y_check_cookie
glfw3.lib(window.obj) : error LNK2001: unresolved external symbol __secur
ity_check_cookie
glfw3.lib(context.obj) : error LNK2001: unresolved external symbol __secu
rity_check_cookie
glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol
 __security_cookie
glfw3.lib(wgl_context.obj) : error LNK2001: unresolved external symbol __
security_cookie
glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol __
security_cookie
glfw3.lib(osmesa_context.obj) : error LNK2001: unresolved external symbol
 __security_cookie
glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __securi
ty_cookie
glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol __s
ecurity_cookie
glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol
__security_cookie
glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol _
_security_cookie
glad.obj : error LNK2001: unresolved external symbol __security_cookie
glfw3.lib(init.obj) : error LNK2001: unresolved external symbol __securit
y_cookie
glfw3.lib(window.obj) : error LNK2001: unresolved external symbol __secur
ity_cookie
glfw3.lib(context.obj) : error LNK2001: unresolved external symbol __secu
rity_cookie
LINK : error LNK2001: unresolved external symbol mainCRTStartup
glfw3.lib(win32_joystick.obj) : error LNK2019: unresolved external symbol
 __imp_calloc referenced in function _glfwInitJoysticksWin32
glfw3.lib(wgl_context.obj) : error LNK2001: unresolved external symbol __
imp_calloc
glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol __
imp_calloc
glfw3.lib(osmesa_context.obj) : error LNK2001: unresolved external symbol
 __imp_calloc
glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol
__imp_calloc
glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol __imp_
calloc
glfw3.lib(vulkan.obj) : error LNK2001: unresolved external symbol __imp_c
alloc
glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol _
_imp_calloc
glfw3.lib(init.obj) : error LNK2001: unresolved external symbol __imp_cal
loc
glfw3.lib(window.obj) : error LNK2001: unresolved external symbol __imp_c
alloc
glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_ca
lloc
glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol __i
mp_calloc
glfw3.lib(win32_joystick.obj) : error LNK2019: unresolved external symbol
 __imp_free referenced in function deviceCallback
glfw3.lib(wgl_context.obj) : error LNK2001: unresolved external symbol __
imp_free
glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol __
imp_free
glfw3.lib(osmesa_context.obj) : error LNK2001: unresolved external symbol
 __imp_free
glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol
__imp_free
glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol __imp_
free
glfw3.lib(vulkan.obj) : error LNK2001: unresolved external symbol __imp_f
ree
glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol _
_imp_free
glfw3.lib(init.obj) : error LNK2001: unresolved external symbol __imp_fre
e
glfw3.lib(window.obj) : error LNK2001: unresolved external symbol __imp_f
ree
glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_fr
ee
glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol __i
mp_free
glfw3.lib(init.obj) : error LNK2019: unresolved external symbol __imp___s
tdio_common_vsprintf referenced in function _glfwInputError
glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol
 __imp___stdio_common_vsprintf
glfw3.lib(win32_monitor.obj) : error LNK2019: unresolved external symbol
memset referenced in function _glfwPlatformGetVideoMode
glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol
 memset
glfw3.lib(init.obj) : error LNK2001: unresolved external symbol memset
glfw3.lib(window.obj) : error LNK2001: unresolved external symbol memset
glfw3.lib(input.obj) : error LNK2001: unresolved external symbol memset
glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol mem
set
glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol _fltus
ed
glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol _
fltused
glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol
 _fltused
glfw3.lib(init.obj) : error LNK2001: unresolved external symbol _fltused
glfw3.lib(window.obj) : error LNK2001: unresolved external symbol _fltuse
d
glfw3.lib(input.obj) : error LNK2001: unresolved external symbol _fltused
glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol
_fltused
glfw3.lib(window.obj) : error LNK2019: unresolved external symbol __imp_s
trncpy referenced in function glfwWindowHintString
glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_st
rncpy
glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol __imp_
strncpy
glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol
 __imp_strncpy
glfw3.lib(context.obj) : error LNK2019: unresolved external symbol strstr
 referenced in function _glfwStringInExtensionString
glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol
 strstr
glfw3.lib(context.obj) : error LNK2019: unresolved external symbol __imp_
strncmp referenced in function _glfwRefreshContextAttribs
glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_st
rncmp
glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol __
imp_strncmp
glfw3.lib(context.obj) : error LNK2019: unresolved external symbol __imp_
__stdio_common_vsscanf referenced in function sscanf
glfw3.lib(input.obj) : error LNK2019: unresolved external symbol __imp_st
rcspn referenced in function glfwUpdateGamepadMappings
glfw3.lib(input.obj) : error LNK2019: unresolved external symbol __imp_st
rspn referenced in function glfwUpdateGamepadMappings
glfw3.lib(input.obj) : error LNK2019: unresolved external symbol __imp_re
alloc referenced in function glfwUpdateGamepadMappings
glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol
__imp_realloc
glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol __imp_
realloc
glfw3.lib(input.obj) : error LNK2019: unresolved external symbol __imp_st
rtoul referenced in function parseMapping
glfw3.lib(monitor.obj) : error LNK2019: unresolved external symbol __imp_
qsort referenced in function refreshVideoModes
glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol
 __imp_qsort
glfw3.lib(monitor.obj) : error LNK2019: unresolved external symbol memmov
e referenced in function _glfwInputMonitor
glfw3.lib(monitor.obj) : error LNK2019: unresolved external symbol powf r
eferenced in function glfwSetGamma
glfw3.lib(vulkan.obj) : error LNK2019: unresolved external symbol strcmp
referenced in function _glfwInitVulkan
glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol
 strcmp
glad.exe : fatal error LNK1120: 27 unresolved externals



Solution

  • I managed to solve this, by adding this to my batch file:

    @echo off
    
    if not exist bin mkdir bin
    
    pushd bin
    
    set LIBRARIES=glfw3.lib user32.lib gdi32.lib shell32.lib
    cl /MDd /FC /Zi /O2 /I..\include ..\main.c C:\Dev\opengl\include\glad\glad.c /link /NODEFAULTLIB:msvcrt.lib /LIBPATH:..\deps\lib-vc2022\ %LIBRARIES%
    
    popd