I work on windows and I am trying to make it easier to install and use libraries for C bindings. On windows, one of the easiest ways to install libraries is via vcpkg. This libraries purpose is to help to find vcpkg installed libraries
Vcpkg.find_package(“zlib”) . If it is installed it will return a Vcpkg::Library with link_paths, dll_paths ,as well as the triplet used.
module Vcpkg
# Details of a package that was found
class Library
# Paths for the linker to search for static or import libraries
property link_paths = [] of Path
# Paths to search at runtme to find DLLs
property dll_paths = [] of Path
# Paths to include files
property include_paths = [] of Path
# crystal: metadata lines
property crystal_metadata = [] of String
# libraries found are static
property is_static = false
# DLLs found
property found_dlls = [] of Path
# static libs or import libs found
property found_libs = [] of Path
# link name of libraries found, this is useful to emit linker commands
property found_names = [] of String
# ports that are providing the libraries to link to, in port link order
property ports = [] of String
# the vcpkg triplet that has been selected
property vcpkg_triplet = ""
def initialize(@is_static, @vcpkg_triplet)
end
end
end
The next step and one I want feedback on is how to link this with the crystal build
or 'shards build` step. I want to know what is the best way to use it like the pkg-config support we have now
4 Likes
This looks nice. I’m not very familiar with a Windows development environment, but it seems like a decent alternative to pkg-config
.
Using it when building Crystal programs requires compiler support, though. Currently the compiler only supports pkg-config
on Unix-like system. On Windows, all library paths need to be declared explicitly.
I think this could potentially work if vcpkg-cr
installed packages into a predefined library path like CRYSTAL_LIBRARY_PATH
.
yeah, I was hoping to start a discussion on making the compiler more os agnostic now that we have windows support coming along. Would like to start using some of the shards with C bindings but most assume bash shell (make with bash commands) .
Is this something I can integrate into raylib-cr to make install easier?
i installed raylib with vcpkg install raylib
. using vcpkg-find raylib -l dll
it outputs
c:\windows_home\documents>vcpkg-find raylib -l dll
Found library raylib
Include paths:
c:\windows_home\vcpkg\installed\x64-windows\include
Library paths:
c:\windows_home\vcpkg\installed\x64-windows\lib
Runtime Library paths:
c:\windows_home\vcpkg\installed\x64-windows\bin
Crystal metadata:
crystal:rustc-link-search=native=c:\windows_home\vcpkg\installed\x64-windows\lib
crystal:rustc-link-search=native=c:\windows_home\vcpkg\installed\x64-windows\bin
Found DLLs:
c:\windows_home\vcpkg\installed\x64-windows\bin\./raylib.dll
c:\windows_home\vcpkg\installed\x64-windows\bin\..\debug\bin/raylib.dll
from examples\collisionarea
I run shards build
c:\windows_home\src\crystal_repos\raylib-cr\examples\collisionarea>shards build
Dependencies are satisfied
Building: main
Error target main failed to compile:
Error: Cannot locate the .lib files for the following libraries: raylib
after running
set CRYSTAL_LIBRARY_PATH=c:\windows_home\vcpkg\installed\x64-windows\lib
c:\windows_home\src\crystal_repos\raylib-cr\examples\collisionarea>shards build
Dependencies are satisfied
Building: main`c:\windows_home\src\crystal_repos\raylib-cr\examples\collisionarea>set CRYSTAL_LIBRARY_PATH=c:\windows_home\vcpkg\installed\x64-windows\lib
Error target main failed to compile:
Error: Cannot locate the .lib files for the following libraries: gc
So, it can find the raylib libraries but I don’t know where it is trying to link to gc
. What library is gc
?
libgc
is usually distributed with Crystal and available in Crystal’s lib path. But overriding CRYSTAL_LIBRARY_PATH
hides it from the compiler. That variable should only be used to if you want to explicitly override the compiler’s default path where it looks for these packaged libraries.
Instead you probably just want to add the lib path for raylib additional to the default configuration. You can do that by passing --link-flags=/LIBPATH:c:\windows_home\vcpkg\installed\x64-windows\lib
to the Crystal compiler, for example.
c:\windows_home\src\crystal_repos\raylib-cr\examples\collisionarea>shards build --link-flags=/LIBPATH:c:/windows_home/vcpkg/installed/x64-windows/lib
Dependencies are satisfied
Building: main
c:\windows_home\src\crystal_repos\raylib-cr\examples\collisionarea>bin\main.exe
c:\windows_home\src\crystal_repos\raylib-cr\examples\collisionarea>copy c:\windows_home\vcpkg\installed\x64-windows\bin\raylib.dll bin
1 file(s) copied.
c:\windows_home\src\crystal_repos\raylib-cr\examples\collisionarea>bin\main.exe
INFO: Initializing raylib 5.0
INFO: Platform backend: DESKTOP (GLFW)
INFO: Supported raylib modules:
INFO: > rcore:..... loaded (mandatory)
INFO: > rlgl:...... loaded (mandatory)
INFO: > rshapes:... loaded (optional)
INFO: > rtextures:. loaded (optional)
INFO: > rtext:..... loaded (optional)
INFO: > rmodels:... loaded (optional)
INFO: > raudio:.... loaded (optional)
INFO: DISPLAY: Device initialized successfully
INFO: > Display size: 2560 x 1440
INFO: > Screen size: 800 x 450
INFO: > Render size: 800 x 450
INFO: > Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: GL: Supported extensions count: 244
INFO: GL: OpenGL device information:
INFO: > Vendor: Intel
INFO: > Renderer: Intel(R) UHD Graphics 770
INFO: > Version: 3.3.0 - Build 31.0.101.4255
INFO: > GLSL: 3.30 - Build 31.0.101.4255
INFO: GL: VAO extension detected, VAO functions loaded successfully
INFO: GL: NPOT textures extension detected, full NPOT textures supported
INFO: GL: DXT compressed textures supported
INFO: GL: ETC2/EAC compressed textures supported
INFO: PLATFORM: DESKTOP (GLFW): Initialized successfully
INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 1] Default texture loaded successfully
INFO: SHADER: [ID 1] Vertex shader compiled successfully
INFO: SHADER: [ID 2] Fragment shader compiled successfully
INFO: SHADER: [ID 3] Program shader loaded successfully
INFO: SHADER: [ID 3] Default shader loaded successfully
INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
INFO: RLGL: Default OpenGL state initialized successfully
INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
INFO: FONT: Default font loaded successfully (224 glyphs)
INFO: TIMER: Target time per frame: 16.667 milliseconds
INFO: TEXTURE: [ID 2] Unloaded texture data from VRAM (GPU)
INFO: SHADER: [ID 3] Default shader unloaded successfully
INFO: TEXTURE: [ID 1] Default texture unloaded successfully
INFO: Window closed successfully
1 Like