I have a make files that generates a library like the following
> file libdevelutils.a && ar -t libdevelutils.a
libdevelutils.a: current ar archive
nonstd.o
testing.o
threads.o
loadingbarPretty.o
loadingbar.o
typecast.o
stream.o
The recipe in my make file looks like this (summarized for showing purposes)
$(STATIC): $(RELEASE_OBJ)
@echo "[$(CC)] $@"
ar rcs $@ $(RELEASE_OBJ)
I have been trying to generate a build.zig that generates the equivalent .a output but I instead generate something that looks like this
> zig build && file zig-out/lib/libstringcore.a && nm zig-out/lib/libstringcore.a
zig-out/lib/libstringcore.a: current ar archive
bfd plugin: LLVM gold plugin has failed to create LTO module: Opaque pointers are only supported in -opaque-pointers mode (Producer: 'LLVM21.1.0' Reader: 'LLVM 14.0.6')
.zig-cache/o/06a7d78b2967e1e869062b95f9907b95/stringCore.o:
nm: .zig-cache/o/06a7d78b2967e1e869062b95f9907b95/stringCore.o: no symbols
When i try to use this output, the linker fails giving me this message
/usr/bin/ld: /usr/lib/nonstd/libstringcore.a: error adding symbols: file format not recognized
collect2: error: ld returned 1 exit status
make: *** [makefile:25: blt] Error 1
This is the part of my build.zig that I thought was supposed to make my archive but it is not working
const source_files = collectSourceFiles(
b,
"src",
".c",
.initComptime(.{.{ "tester.c", 0 }}),
) catch @panic("Failed to collect source files\n");
const lib = b.addLibrary(.{
.name = lib_name,
.linkage = .static,
.root_module = b.createModule(.{
.link_libc = true,
.optimize = optimize,
.target = target,
}),
});
lib.root_module.addCSourceFiles(
.{ .files = source_files, .flags = flags, .language = .c },
);
b.installArtifact(lib);
I know I don’t fully understand the modules part of the build system. Am i wrong to use a module when creating a static library to be used with c?