[Zig]Solution for common issues
keywords: Zig common issues
Compiling & Building
Unable to spawn glslc: InvalidName
Error on building:
Unable to spawn glslc: InvalidName
Solution:
Download glslc binaries or compiling it from source, then add glslc.exe
system environment variables.
https://github.com/google/shaderc
error: invalid carriage return, only ‘\n’ line endings are supported
Error on source building:
error: invalid carriage return, only '\n' line endings are supported
const std = @import("std");
Solution:
Execute fmt
command to use Unix line ending in source files:
zig fmt test.zig
Or, modify source file in Notepad++: Edit -> EOL Conversion -> Unix(LF).
Origin:
https://github.com/ziglang/zig/issues/544
glfw3.h:171:12: note: ‘GL/gl.h’ file not found
Building Error:
glfw3.h:171:12: note: 'GL/gl.h' file not found
Solution:
Add define GLFW_INCLUDE_NONE
in glfw3.h
:
#if !defined(GLFW_INCLUDE_NONE)
#define GLFW_INCLUDE_NONE
#endif
lld: error: undefined symbol: __imp_calloc
Building Error:
lld: error: undefined symbol: __imp_calloc
>>> referenced by glfw3.lib(window.c.obj):($LN21)
>>> referenced by glfw3.lib(input.c.obj):($LN7)
>>> referenced by glfw3.lib(input.c.obj):($LN9)
>>> referenced by glfw3.lib(win32_init.c.obj):($LN7)
>>> referenced by glfw3.lib(win32_init.c.obj):($LN7)
>>> referenced by glfw3.lib(win32_monitor.c.obj):($LN35)
>>> referenced by glfw3.lib(monitor.c.obj):($LN4)
>>> referenced by glfw3.lib(monitor.c.obj):($LN4)
>>> referenced by glfw3.lib(monitor.c.obj):($LN4)
>>> referenced by glfw3.lib(monitor.c.obj):($LN4)
>>> referenced 13 more times
Solution:
Turn off DUSE_MSVC_RUNTIME_LIBRARY_DLL
when building with cmake.
cmake command:
cmake -DBUILD_SHARED_LIBS=OFF -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_DOCS=OFF -DUSE_MSVC_RUNTIME_LIBRARY_DLL=OFF -G "Visual Studio 16 2019" -A x64
MSBuild GLFW.sln /p:Configuration=Release /p:Platform=x64
Origin:
Link errors when linking with C static library (GLFW) on Windows
https://github.com/ziglang/zig/issues/2911
lld: error: undefined symbol: __imp_TranslateMessage
Building Error:
D:\workspace\zigdev\glfw_test>zig build
lld: error: undefined symbol: __imp_TranslateMessage
>>> referenced by glfw3.lib(win32_init.obj):($LN40)
>>> referenced by glfw3.lib(win32_window.obj):($LN33)
Solution:
Add dependency of User32
in build.zig
:
exe.addLibPath("D:/Program_Filesx86/Windows Kits/10/Lib/10.0.18362.0/um/x64");
exe.linkSystemLibrary("User32");
诸将易得耳,至如信者,国士无双。——司马迁《史记·淮阴侯列传》