ncurses is a dependency of your libgame.so , not a main executable. Therefore, if you unload the dynamic library and download the modified version, you will also unload ncurses and then download it again. But you cannot reinitialize it. This is why your program crashes.
The correct solution is to call endwin() in game_unload to clear the ncurses state, and then reinitialize it in game_reload :
static void game_reload(struct game_state *state) { initscr(); raw(); timeout(0); noecho(); curs_set(0); keypad(stdscr, TRUE); } static void game_unload(struct game_state *state) { endwin(); }
Another solution would be to force the linker to bind ncurses to the main executable. This will prevent the dynamic linker from unloading when the game library is unloaded. This can be done by adding the -Wl,--no-as-needed flag before the $(LDLIBS) variable when compiling the main executable:
main : main.c game.h $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -Wl,--no-as-needed $(LDLIBS)
If you prefer this solution, also consider moving the ncurses initialization / cleanup to the main.c file. There is no technical reason for this; it is simply a matter of pure coding style.
source share