Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unresolved external Symbols and Linker Errors when building application with GLFW with clang on windows #1981

Closed
QLavi opened this issue Oct 28, 2021 · 9 comments
Assignees
Labels
build Build file bugs and PRs (not compilation errors) support Windows Win32 specific (not Cygwin or WSL)
Milestone

Comments

@QLavi
Copy link

QLavi commented Oct 28, 2021

I used cmake and ninja.

OS and version: Windows 10 Build 19043
Compiler version: clang version 13.0.0
Release or commit: fb0f2f92a38c1d6a776ffeb253329f8d1c65694c
Build log:

[1/1] Linking target hello.exe
FAILED: hello.exe hello.pdb 
"clang"  -Wl,/MACHINE:X64 -Wl,/OUT:hello.exe hello.exe.p/src_main.c.obj "-Wl,/nologo" "-Wl,/release" "-Wl,/nologo" "-Wl,/DEBUG" "-Wl,/PDB:hello.pdb" "-L..\lib" "-lglfw3" "-Wl,/SUBSYSTEM:CONSOLE" "-lkernel32" "-luser32" "-lgdi32" "-lwinspool" "-lshell32" "-lole32" "-loleaut32" "-luuid" "-lcomdlg32" "-ladvapi32"
LINK : warning LNK4098: defaultlib 'msvcrtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4217: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'glfw3.lib(init.c.obj)' in function 'vsnprintf'
LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'glfw3.lib(context.c.obj)'
LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'glfw3.lib(egl_context.c.obj)'
LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'glfw3.lib(win32_joystick.c.obj)'
LINK : warning LNK4217: symbol 'malloc' defined in 'libucrt.lib(malloc.obj)' is imported by 'glfw3.lib(init.c.obj)' in function 'defaultAllocate'
LINK : warning LNK4217: symbol 'free' defined in 'libucrt.lib(free.obj)' is imported by 'glfw3.lib(init.c.obj)' in function 'defaultDeallocate'
LINK : warning LNK4286: symbol 'free' defined in 'libucrt.lib(free.obj)' is imported by 'glfw3.lib(null_init.c.obj)'
LINK : warning LNK4217: symbol 'strncmp' defined in 'libucrt.lib(strncmp.obj)' is imported by 'glfw3.lib(input.c.obj)' in function 'parseMapping'
LINK : warning LNK4286: symbol 'strncmp' defined in 'libucrt.lib(strncmp.obj)' is imported by 'glfw3.lib(context.c.obj)'
LINK : warning LNK4286: symbol 'strncmp' defined in 'libucrt.lib(strncmp.obj)' is imported by 'glfw3.lib(egl_context.c.obj)'
LINK : warning LNK4217: symbol 'strtoul' defined in 'libucrt.lib(strtox.obj)' is imported by 'glfw3.lib(input.c.obj)' in function 'parseMapping'
LINK : warning LNK4217: symbol 'qsort' defined in 'libucrt.lib(qsort.obj)' is imported by 'glfw3.lib(monitor.c.obj)' in function 'refreshVideoModes'
LINK : warning LNK4217: symbol 'qsort' defined in 'libucrt.lib(qsort.obj)' is imported by 'glfw3.lib(win32_joystick.c.obj)' in function '_glfwGetMappingNameWin32'
LINK : warning LNK4217: symbol 'wcscmp' defined in 'libucrt.lib(wcscmp.obj)' is imported by 'glfw3.lib(win32_monitor.c.obj)' in function '_glfwPollMonitorsWin32'
glfw3.lib(init.c.obj) : error LNK2019: unresolved external symbol __imp_realloc referenced in function defaultReallocate
glfw3.lib(wgl_context.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
glfw3.lib(vulkan.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
glfw3.lib(context.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
glfw3.lib(osmesa_context.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
glfw3.lib(egl_context.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
glfw3.lib(window.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
glfw3.lib(win32_thread.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
glfw3.lib(input.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
glfw3.lib(monitor.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
glfw3.lib(window.c.obj) : error LNK2019: unresolved external symbol __imp_strncpy referenced in function glfwWindowHintString
glfw3.lib(input.c.obj) : error LNK2001: unresolved external symbol __imp_strncpy
glfw3.lib(monitor.c.obj) : error LNK2001: unresolved external symbol __imp_strncpy
glfw3.lib(win32_joystick.c.obj) : error LNK2001: unresolved external symbol __imp_strncpy
glfw3.lib(input.c.obj) : error LNK2019: unresolved external symbol __imp_strcspn referenced in function parseMapping
glfw3.lib(input.c.obj) : error LNK2019: unresolved external symbol __imp_strspn referenced in function parseMapping
glfw3.lib(monitor.c.obj) : error LNK2019: unresolved external symbol __imp_powf referenced in function glfwSetGamma
glfw3.lib(null_monitor.c.obj) : error LNK2001: unresolved external symbol __imp_powf
glfw3.lib(context.c.obj) : error LNK2019: unresolved external symbol __imp___stdio_common_vsscanf referenced in function _vsscanf_l
glfw3.lib(win32_monitor.c.obj) : error LNK2019: unresolved external symbol __imp_wcscpy referenced in function createMonitor
hello.exe : fatal error LNK1120: 8 unresolved externals
clang: error: linker command failed with exit code 1120 (use -v to see invocation)
ninja: build stopped: subcommand failed.
@QLavi QLavi changed the title Unresolved resolved external Symbols and Linker Errors when building GLFW with clang on windows Unresolved external Symbols and Linker Errors when building GLFW with clang on windows Oct 28, 2021
@elmindreda elmindreda added build Build file bugs and PRs (not compilation errors) Windows Win32 specific (not Cygwin or WSL) labels Oct 28, 2021
@QLavi
Copy link
Author

QLavi commented Oct 28, 2021

my apologies.. I think didn't correctly described the issue :/
problem is with building application when GLFW is built as static lib using CMake +Ninja and using Clang 13.
I used Meson + Ninja to build my application and I tried to link with glfw3.lib and then I got these errors and warnings.
issue is with static lib.
I do not get these errors/warning when GLFW is build using BUILD_SHARED_LIBS.

@QLavi QLavi changed the title Unresolved external Symbols and Linker Errors when building GLFW with clang on windows Unresolved external Symbols and Linker Errors when building application with GLFW with clang on windows Oct 28, 2021
@elmindreda elmindreda self-assigned this Oct 28, 2021
@elmindreda
Copy link
Member

It looks like you are using a GLFW library file compiled for the DLL form of the UCRT while your application is being compiled for the static library form.

If you are using an archive of precompiled files from our release page, use the glfw3_mt.lib file instead of the glfw3.lib one.

@QLavi
Copy link
Author

QLavi commented Oct 28, 2021

I am not using precompiled files.

It looks like you are using a GLFW library file compiled for the DLL form of the UCRT while your application is being compiled for the static library form.

I am not sure what you mean by that.

here is what I am using to build the app.

project('GLFW_LIB_PLAY', 'c')

glfw_dep = declare_dependency(link_args: ['-L..\lib', '-lglfw3'], include_directories: 'include/')
src = ['src/main.c']
executable('hello', sources: src, dependencies: glfw_dep)

I did make sure BUILD_SHARED_LIB was off. when compiling GLFW.

@QLavi
Copy link
Author

QLavi commented Oct 28, 2021

okay I understood what you meant by that.
and now it works with glfw3_mt.lib
how should I go about compiling GLFW so it compiles using statically linked UCRT?

@elmindreda
Copy link
Member

It depends, what tools are you using to compile GLFW?

@QLavi
Copy link
Author

QLavi commented Oct 29, 2021

Cmake + ninja and clang.

@elmindreda
Copy link
Member

The version of CMake I tested this on (3.21.0) honored the standard CMAKE_MSVC_RUNTIME_LIBRARY variable when generating for Ninja and Clang. You want to set it to "MultiThreaded$<$<CONFIG:Debug>:Debug>" to use the correct static library form.

@QLavi
Copy link
Author

QLavi commented Nov 3, 2021

Alright! Thank you.

@JuanmaDevG
Copy link

I have a doubt about this issue.

Does this mean that the right way to compile the glfw source code using more modern versions of cmake is to set that really long variable to that really long value?

Shouldn't the BUILD_SHARED_LIB variable give enough information to cmake to build the static multithreading version of glfw?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Build file bugs and PRs (not compilation errors) support Windows Win32 specific (not Cygwin or WSL)
Projects
None yet
Development

No branches or pull requests

3 participants