How to program ATmega 328P - PU
You can use Arduino as ISP programmer. Check the Arduino IDE \$\Rightarrow\$ File \$\Rightarrow\$ Examples \$\Rightarrow\$ ArduinoISP and refer to ArduinoISP documentation.

I personally use Linux and a Makefile to run all the required commands.

In short these are the commands required (Linux, but Windows is pretty similar when the toolchain is installed [and it is if you have the ArduinoIDE on the system])

#edit
# use your favorite text editor to author the source file, then save as `project.cpp`

#variables
src=project
programmerType=arduino
programmerDevice=/dev/.......fill.this.in....
avrFreq=16000000
avrType=attiny45
baudrate=19200
cflags="-g -DF_CPU=$(avrFreq) -Wall -Os -Werror -Wextra -ffunction-sections -fdata-sections"

#compile to object
avr-gcc $cflags -mmcu=$avrType -Wa,-ahlmns=${src)}.lst -c -o ${src}.o ${src}.cpp

#compile to elf
avr-gcc $cflags -mmcu=$avrType -o ${src}.elf ${src}.o

#encode binary file to intelHex
avr-objcopy -j .text -j .data -O ihex ${src}.elf ${src}.flash.hex

#flash the controller
avrdude -p$avrType -c$programmerType -P$programmerDev $(baud) -v -U flash:w:${src}.flash.hex


Seeing the complexity to remember these commands, it really pays off to figure out how to use the linked above makefile on your system:

make help
make edit
make flash