Skip to content

cj1128/hot-reload-c

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 

Hot Reload C

A simple SDL2 program to demonstrate how to hot reload C.

demo.mp4

Build

This program can be built on MacOS and Linux.

First you need to install SDL2:

  • MacOS: brew install sdl2
  • Linux: Check your package manager, e.g. on Manjaro, pacman -S sdl2

Then clone the code and build

$ git clone ... && cd ...
$ make run
# while the program is running, modify render.c and rebuild
$ make build
# and then the program will be hot reloaded πŸš€

Idea

The main idea behind this is Shared Library a.k.a Dynamic Loaded Library.

We compile the render logic into a separate shared library and load it in main program dynamically via these apis:

  • dlopen
  • dlclose
  • dlsym

So while the main program is running, we can rebuild our render library to hot load the main program.

Google dynamic linking for more details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published