Zig cc to assembly

How do i tell zig to compile a .c file to .s (assembly).
I tried:
zig cc -emit-llvm -fverbose-asm
but i get undefined symbols

Undefined symbols sounds like you might be missing some “include directories”, but that’s just a guess without more information. Including the exact error message would help, including the code to reproduce would be even more helpful.

I did not specified the parameter “-c” so it tries to build an executable i think.
But if i specify “-c & -S” nothing happens. No assembly file is written.
To refrase my question, which parameters should i place after the zig command for it in order to produce readable assembly code.

Here’s an example:


#include <stdio.h>

int main()
  return 0;

zig cc -S hello.c


	.file	"hello.c"
	.globl	main                            # -- Begin function main
	.p2align	4, 0x90
	.type	main,@function
main:                                   # @main
# %bb.0:
	pushq	%rbp
	movq	%rsp, %rbp
	leaq	.Lstr(%rip), %rdi
	callq	puts@PLT
	xorl	%eax, %eax
	popq	%rbp
	.size	main, .Lfunc_end0-main
                                        # -- End function
	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
	.asciz	"hello"
	.size	.Lstr, 6

	.ident	"clang version 13.0.0 (git@github.com:ziglang/zig-bootstrap.git 4cced909c6506a6eb96e55ba5c31f883fe8208a1)"
	.section	".note.GNU-stack","",@progbits

Also if you have a binary, you can use objdump -d BINARY to dump the assembly of a compiled binary. Very useful sometimes.