#C library not detected when linked on Windows

1 messages · Page 1 of 1 (latest)

steel osprey
#

I'm currently trying to use the GLFW library in zig. I know it's not the best way to go about things, but I'm currently just porting over a C++ program to zig to get a good feel for the language. I've tried to add it through the commands using --library glfw3 and using build.zig, but nothing seems to work. Most answers are for linux online, so i'm not able to get much help anywhere else.

#

ive also tried using the build.zig file like this:

    const exe = b.addExecutable(.{
        .name = "Minecraft",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });

    const zstbi = b.dependency("zstbi", .{});
    exe.root_module.addImport("zstbi", zstbi.module("root"));
    exe.linkLibrary(zstbi.artifact("zstbi"));

    exe.addIncludePath("C:/msys64/ucrt64/include/");
    exe.addLibraryPath("C:/msys64/ucrt64/bin/");

    exe.linkSystemLibrary("glfw3");
    exe.linkSystemLibrary("opengl32");
    exe.linkSystemLibrary("glu32");
    
    b.installArtifact(exe);
#

i dont really understand this, this is my first time using C libraries with this

steel osprey
#

am i asking the wrong question?

#

How do you link in Windows libraries?

#

How do you link in C libraries?

#

How do you link in C libraries on Windows?

steel osprey
#

im gonna go insane

#

C library not detected when linked on Windows

lilac furnace
#

whats the error? just guessing, you may need to use exe.addIncludePath to the include path of glfw3, opengl32, glu32. i dont think its neccecary to add the path for msys64 (ucrt) paths, since the standard library should be done for you

steel osprey
#

C:/msys64/ucrt64/include/ is the include path for all of those

lilac furnace
#

oh sorry i didnt read before sending, include path for headers (.h files), then library path to the dir containing .dll / .a files

#

maybe lib instead of bin, if it exists?

steel osprey
#

i did use the incorrect path there

#

but i think the main issue is idk how to use it after that

lilac furnace
#

zig build?

steel osprey
#

i mean in the code

lilac furnace
steel osprey
#

so it is just like that huh

#

alright ill see if it works, but as of now, thank you

lilac furnace
#

to use the translate-c version, it takes a .h file. in a few zig releases, this will be the preferred way of doing things and cImport will be removed.

    const translate_c = b.addTranslateC(.{
        .root_source_file = b.path("c-libraries.h"),
        .target = target,
        .optimize = optimize,
        .link_libc = true,
    });
    translate_c.addIncludePath(...);
    // ... configure the step ...
    exe.root_module.addImport("c", translate_c.createModule());

usage

const c = @import("c");
steel osprey
#

idk how much trouble ill get into later cause of stupidity lol

#

oh i have both .a and .h files

lilac furnace
#

.h (c header) is a definition of what symbols are in the .a (posix static library "archive") file

steel osprey
#

yeah that makes sense

#

ive mainly used C lol

lilac furnace
#

also something to consider is bindings for those libraries there are for sure nicer zig bindings that wrap the API to use slices and zig error types, i know one for glfw exists.

#

these libraries also build everything from source

steel osprey
#

i know there are nicer ones, but they change how things work

lilac furnace
#

tho its reasonable to just use the c layer especially when starting, it builds understanding

steel osprey
#

and also zig's library manager is absolute garbage to work through at my level of understanding

lilac furnace
#

its a very simple file downloader, needs much more tooling

steel osprey
#

it dont even work, i use it, put it in my program, dont even read it

#

i fixed that tho