I'm trying to link a zig static library with golang. here is my build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
const windows = b.option(bool, "windows", "Target Microsoft Windows") orelse false;
const arm64 = b.option(bool, "arm64", "Target ARM64 architecture") orelse false;
const target = b.resolveTargetQuery(.{
.cpu_arch = if (arm64) .aarch64 else if (windows) .x86_64 else null,
.os_tag = if (windows) .windows else null,
});
const optimize = b.standardOptimizeOption(.{});
const zigwin32 = b.dependency("zigwin32", .{});
const lib = b.addStaticLibrary(.{
.name = "myziglib",
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
});
lib.root_module.addImport("zigwin32", zigwin32.module("win32"));
b.installArtifact(lib);
const exe = b.addExecutable(.{
.name = "myapp",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("zigwin32", zigwin32.module("win32"));
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
b.step("run", "Run the app").dependOn(&run_cmd.step);
}
I want to use this in my go program with the following #cgo LDFLAGS: -L./zig1/zig-out/lib -lmyziglib
I compile Zig with - zig build -Dwindows=true -Darm64=true
I compile then golang with - GOOS=windows GOARCH=arm64 CGO_ENABLED=1 \ CC="zig cc -target aarch64-windows-gnu" \ go build -o main.exe .
I get the following errors -
lld-link: error: duplicate symbol: _tls_end
>>> defined at myziglib.lib(myziglib.lib.obj)
>>> defined at libmingw32.lib(tlssup.obj)
lld-link: error: duplicate symbol: __xl_a
>>> defined at myziglib.lib(myziglib.lib.obj)
>>> defined at libmingw32.lib(tlssup.obj)
lld-link: error: duplicate symbol: __xl_z
>>> defined at myziglib.lib(myziglib.lib.obj)
>>> defined at libmingw32.lib(tlssup.obj)
lld-link: error: duplicate symbol: _tls_used
>>> defined at myziglib.lib(myziglib.lib.obj)
>>> defined at libmingw32.lib(tlssup.obj)
Any ideas? I was able to link go and zig with a simple program. but I soon as i started using win32 I started to get this error