I would like to include sounds in the game Breakout. I tried a simple test to get a sound file to play with the following code:

#include "sound.h"

int main(void)
    Sound paddle_sound = newSound("paddle_sound.wav");


    return 0;

However, When I try to compile I am told:

clang -ggdb3 -Ispl/include -O0 -std=c99 -Wall -Werror -Wno-unused-variable -o soundtest soundtest.c -Lspl/lib -lcs -lm
/tmp/soundtest-DV2kS4.o: In function `main_':
/home/jharvard/Dropbox/pset4/soundtest.c:19: undefined reference to `play'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Isn't 'play' referenced in the sound.h file and defined in the SPL? Does anyone have any suggestions?

  • I'm not sure if I'm correct, but I think this tells us that the code for play isn't included into libcs.a (i.e., it wasn't compiled).
    – kzidane
    Nov 29 '14 at 8:07
  • I am still working to understand libraries and linking, so maybe I am way off base here. I hope the following terminology is correct. The Stanford cslib package contains in its interface files the sound.h header file, where the play(sound) function is declared. Is clang telling me that the spl/lib object code does not have the definition for play(sound), even though it is declared in the header file? Do I have a partial version of spl/lib for CS50 that does not include all of the interface files?
    – jackacid
    Nov 29 '14 at 17:50
  • Probably yes and yes.
    – kzidane
    Nov 29 '14 at 19:21

You must log in to answer this question.

Browse other questions tagged .