Issues statically linking IUP

I am attempting to statically link to the IUP UI library, using their provided MinGW binaries. I’ve been able to figure it out except for 3 linker errors. Which seem to be compiler implementation specific? I’ve had trouble digging up information on this. Any help would be greatly appreciated.

error: lld-link: undefined symbol: __declspec(dllimport) __argc
    note: referenced by libiup.a(iupwindows_main.o):(.refptr.__imp___argc)
error: lld-link: undefined symbol: __declspec(dllimport) __argv
    note: referenced by libiup.a(iupwindows_main.o):(.refptr.__imp___argv)
error: lld-link: undefined symbol: _setjmp
    note: referenced by libiup.a(iup_maskparse.o):(iupMaskParse)

And these are the libs I’m linking:

  • libc
  • iup
  • gdi32
  • comdlg32
  • comctl32
  • ole32

Hey @SDay, welcome to the forum!

Do you have a build.zig file that you’re working with or a script/command that you can share with us? I think some more information would be helpful!

Of course, thank you. I’m just using a build script. No custom args for zig build or anything.

const std = @import("std");
const Build = std.Build;

pub fn build(b: *Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(.{
        .name = "Data Chronologer",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });
    exe.linkLibC();
    exe.addIncludePath(.{ .path = "include/iup" });
    exe.addLibraryPath(.{ .path = "lib/iup" });
    const libs = [_][]const u8{
        "iup",
        "gdi32",
        "comdlg32",
        "comctl32",
        "ole32",
    };
    for (libs) |lib| {
        exe.linkSystemLibrary(lib);
    }

    b.installArtifact(exe);
    const run_cmd = b.addRunArtifact(exe);
    run_cmd.step.dependOn(b.getInstallStep());
    if (b.args) |args| {
        run_cmd.addArgs(args);
    }
    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);

    const exe_unit_tests = b.addTest(.{
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });

    const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&run_exe_unit_tests.step);
}

I hit the same error yesterday while trying to link a static library that was built with an older zig version.
I’m guessing this was caused by a recent update of of mingw64 in the zig compiler Update mingw-w64 to latest git commit by andrewrk · Pull Request #16109 · ziglang/zig · GitHub
I could solve this by rebuilding the static library with the same zig version. But that would be pretty complicated in your case, I guess.

So I’d suggest that you report this problem on github and either use an older zig version or dynamically link the library until the issue is fixed.

Thank you for this insight. Will try reporting this soon and see if there’s a workaround for linking to older builds from MinGW. But I’ll just do dynamic linking for now. Much appreciated!