-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zig build-lib does not allow linking to a C program #14416
Comments
You have built the library in debug mode. If you build in releaseFast or small mode the error will not occur, or add |
Thanks. |
As documented in ziglang#14416, when using `zig build-lib -femit-h` with caching enabled, if the generated header file is removed, it will not be generated again, unless the library source code is modified. For consistent builds with `zig build`, assume that the file generated by -femit using the default path is an artificact, and update src/main.zig to enable caching. Update the flushEmitH function in src/link/C.zig to use the zig_cache_artifact_directory instead of the incorrect local_cache_directory. Updates ziglang#14416
As documented in ziglang#14416, when using `zig build-lib -femit-h` with caching enabled, if the generated header file is removed, it will not be generated again, unless the library source code is modified. For consistent builds with `zig build`, assume that the file generated by -femit using the default path is an artificact, and update src/main.zig to enable caching. Update the flushEmitH function in src/link/C.zig to use the zig_cache_artifact_directory instead of the incorrect local_cache_directory. Updates ziglang#14416
|
Scratch my last comment. This issue goes away if you explicitly pass |
I converted the 3 different issues into separate tasks. I'm not sure about the last task, since the (currently disabled) |
Hello! With the latest versions of zig on MacOS (I tried version 0.10 and 0.11 and 0.12 and compiled from main/HEAD) this example now segfaults. Instead of opening a new bug I thought I would just add it here.
I added a debug print statement right before this block where the assertion is shown in Module.zig
allocated_emit_h = segmented_list.SegmentedList(Module.EmitH,0) It looks like the situation is (pseudo-code)
If the append succeeds, the assert always fails. |
In the Zig Language Reference there are two example of linking a Zig library to a C program in the "Exporting a C Library" and "Mixing Object Files" sections. Both examples fail.
These are the issues I found:
Static linking using a C compiler fails
Using the
mathtest.zig
exampleI'm not sure if this works as expected. When using
zig build
the generated executable is dynamically linked.See -fcompiler-rt broken with object file builds #14099.
Setting
LibExeObjStep.emit_h
to true, does not emit the header file a second time when the header file is removedWhen
mathtest.h
does not exists,zig build
will create it, but if I remove the file,zig build
will not create it again.The reason is that the build system always enables caching, but the generated header file is not cached in the artifact directory.
See compiler: enable caching for -femit-h #14606.
zig build
should automatically includezig.h
header whenemit_h
is set to true.When an executable links a library with
emit_h
set to true, the build system should automatically append the path tozig_dir
toexe.include_dirs
.See build: include zig.h when CompileStep.emit_h is true #14576.
Thanks.
The text was updated successfully, but these errors were encountered: