0

I wrote a simple Chip-8 emulator in C (mostly taking inspiration from this; to be honest, just rewriting it in C). It uses SDL 2.0, which I definitely have installed.

As I tried compiling the files (gcc main.c chip8.c -o chip8), I got this stack of errors:

Undefined symbols for architecture x86_64:
  "_SDL_CreateRenderer", referenced from:
      _main in main-638d2a.o
  "_SDL_CreateTexture", referenced from:
      _main in main-638d2a.o
  "_SDL_CreateWindow", referenced from:
      _main in main-638d2a.o
  "_SDL_GetError", referenced from:
      _main in main-638d2a.o
  "_SDL_Init", referenced from:
      _main in main-638d2a.o
  "_SDL_PollEvent", referenced from:
      _main in main-638d2a.o
  "_SDL_RenderClear", referenced from:
      _main in main-638d2a.o
  "_SDL_RenderCopy", referenced from:
      _main in main-638d2a.o
  "_SDL_RenderPresent", referenced from:
      _main in main-638d2a.o
  "_SDL_RenderSetLogicalSize", referenced from:
      _main in main-638d2a.o
  "_SDL_UpdateTexture", referenced from:
      _main in main-638d2a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm very sure I used the correct #include (#include "SDL2/SDL.h"). This is my project structure:

chip-8
—— main.c
–– chip8.c
–– chip8.h
–– INVADERS (rom file)

Why doesn't the linker work with this? Are any other compiler flags required?

Clifford
  • 88,407
  • 13
  • 85
  • 165
aachh
  • 93
  • 2
  • 5
  • 2
    Inclusion is not linking, "installing" a library is just copying it to your hard drive. You have to explicitly tell the linker which non-default libraries you are linking. – Clifford Feb 03 '20 at 19:51

1 Answers1

1

Why doesn't the linker work with this? Are any other compiler flags required?

Yes, you need to tell the linker which libraries to link against, e.g.:

-lSDL2

See How to use SDL with gcc?

Acorn
  • 24,970
  • 5
  • 40
  • 69
  • Thanks, this solved my problem. A flag is what I thought was missing, yet I wasn't able to find any information on it. – aachh Feb 03 '20 at 20:07