-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add "main entry in C" documentation section #21945
base: master
Are you sure you want to change the base?
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: