Add "main entry in C" documentation section #21945
Add "main entry in C" documentation section #21945danielchasehooper wants to merge 2 commits intoziglang:masterfrom
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
|
This recommendation comes from Andrew. found here. The example works with zig master on macos. Are you on windows or an older version of zig? |
It probably works on macOS because that uses libc as its system ABI, therefore including it by default iirc. |
|
Ok, added |
gooncreeper
left a comment
There was a problem hiding this comment.
Under Root Source File there is already a relevant TODO: if linking with libc you can use export fn main, you should put the section there and additionally add an example of a C main in Zig.
Since this information is specifically about mixed C/Zig code, I think it belongs in the section about integrating C and Zig. The fact that the solution involves the root source file is incidental.
I do not know how to do a C main in Zig. This PR is about the opposite problem. Would someone with the power to merge mind chiming in? cc @andrewrk @alexrp |
While transitioning a C project to Zig, it tripped me up that Zig expected
main()to be in Zig. Took a while for me to find the workaround. I felt the docs should mention it so others can avoid the same snag.This is what it looks like: