this is the build.zig
const builtin = @import("builtin");
const std = @import("std");
pub fn build(b: *std.Build) !void {
_ = b.allocator;
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
var exe = if (builtin.os.tag == .windows) b.addExecutable(.{
.name = "zig-axmol-test1",
.root_source_file = b.path("src/win_main.zig"),
.target = target,
.optimize = optimize,
}) else {
std.log.err("Only support windows for now.\n", .{});
return;
};
const axmol_libs_path = b.path("axmol_libs");
exe.addLibraryPath(axmol_libs_path);
exe.linkLibC();
// exe.linkLibCpp(); //don't need when the target is msvc
var axmol_libs_files = (try axmol_libs_path.getPath3(b, &exe.step).openDir("", .{ .iterate = true })).iterate();
while (try axmol_libs_files.next()) |entry| {
const LIB_SUFFIX = ".lib";
if (!std.mem.endsWith(u8, entry.name, LIB_SUFFIX)) {
continue;
}
exe.linkSystemLibrary(entry.name[0..(entry.name.len - LIB_SUFFIX.len)]);
}
exe.linkSystemLibrary("Winmm");
exe.linkSystemLibrary("user32");
exe.linkSystemLibrary("advapi32");
exe.linkSystemLibrary("ws2_32");
exe.linkSystemLibrary("uuid");
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);
}
inside axmol_libs
some pre-compiled c++ libraries(.lib) are placed, those were compiled uinsg typical windows MSVC visual studio project.
so after running normal zig build
I get:
error: lld-link: could not open 'libmsvcprtd.a': No such file or directory
error: lld-link: could not open 'libuuid.a': No such file or directory
error: lld-link: could not open 'libMSVCRTD.a': No such file or directory
error: lld-link: could not open 'libOLDNAMES.a': No such file or directory
tried to run zig build -Dtarget=x86_64-windows-msvc
returns the following logs:
error: sub-compilation of libcxxabi failed
:1:1: note: argument unused during compilation: '-nostdinc++'
:1:1: note: argument unused during compilation: '-nostdinc++'
Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:78:8: note: use of undeclared identifier '__libcpp_refstring'
Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:15:10: note: in file included from Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:15:
#include "include/refstring.h" // from libc++
^
Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:89:8: note: use of undeclared identifier '__libcpp_refstring'
Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:15:10: note: in file included from Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:15:
#include "include/refstring.h" // from libc++
^
Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:89:53: note: unknown type name '__libcpp_refstring'
Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:15:10: note: in file included from Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:15:
#include "include/refstring.h" // from libc++
^
Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:94:8: note: unknown type name '__libcpp_refstring'
Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:15:10: note: in file included from Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:15:
#include "include/refstring.h" // from libc++
^
Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:94:28: note: use of undeclared identifier '__libcpp_refstring'
Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:15:10: note: in file included from Z:\Home\.zig\lib\libcxxabi\src/stdlib_stdexcept.cpp:15:
#include "include/refstring.h" // from libc++
<redacted>
running zig version: 0.14.0-dev.622+a84951465
just want some trouble shooting suggestions, what should I try at this point kind of lost.
update:
so when specifying the target to be x86_64-windows-msvc
(eg.zig build -Dtarget=x86_64-windows-msvc
) you don’t need to call exe.linkLibCpp();
, probably because zig tries to link it’s own version of libc++? but now an new issue is the linker can’t seem to find standard function
lld-link: undefined symbol: __declspec(dllimport) strtoul
lld-link: undefined symbol: __declspec(dllimport) ungetc
error: lld-link: undefined symbol: __declspec(dllimport) fopen_s
anything what i am dealing with? feels like my original msvc compiled libs are wrongly compiled?