How to include fmod library to C?

I’m trying to write (as my first ever project) a wav media player in pure C.

I downloaded the library, but i can’t get the example code work.
Im on linux, no IDE.

The code

#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include </home/name/giraffe/fmodstudioapi20218linux/api/core/inc/fmod.h> // This is the absolute path to the downloaded and extracted library
    FSOUND_SAMPLE* handle;
    int main()
     // init FMOD sound system
       FSOUND_Init (44100, 32, 0);
       // load and play mp3
       handle=FSOUND_Sample_Load (0,"./giraffe/kalasnikow.wav",0, 0, 0);
       FSOUND_PlaySound (0,handle);
       // clean up
       FSOUND_Sample_Free (handle);

I tried to compile it with this line:
gcc random.c -L/home/i3hunor/giraffe/fmodstudioapi20218linux/api/core/inc/ -l/home/i3hunor/giraffe/fmodstudioapi20218linux/bin/lib -o random

The error message:

random.c:6:5: error: unknown type name ‘FSOUND_SAMPLE’
    6 |     FSOUND_SAMPLE* handle;
      |     ^~~~~~~~~~~~~
random.c: In function ‘main’:
random.c:10:8: warning: implicit declaration of function ‘FSOUND_Init’ [-Wimplicit-function-declaration]
   10 |        FSOUND_Init (44100, 32, 0);
      |        ^~~~~~~~~~~
random.c:13:15: warning: implicit declaration of function ‘FSOUND_Sample_Load’ [-Wimplicit-function-declaration]
   13 |        handle=FSOUND_Sample_Load (0,"./giraffe/kalasnikow.wav",0, 0, 0);
      |               ^~~~~~~~~~~~~~~~~~
random.c:13:14: warning: assignment to ‘int *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
   13 |        handle=FSOUND_Sample_Load (0,"./giraffe/kalasnikow.wav",0, 0, 0);
      |              ^
random.c:14:8: warning: implicit declaration of function ‘FSOUND_PlaySound’ [-Wimplicit-function-declaration]
   14 |        FSOUND_PlaySound (0,handle);
      |        ^~~~~~~~~~~~~~~~
random.c:17:8: warning: implicit declaration of function ‘FSOUND_Sample_Free’ [-Wimplicit-function-declaration]
   17 |        FSOUND_Sample_Free (handle);
      |        ^~~~~~~~~~~~~~~~~~
random.c:18:8: warning: implicit declaration of function ‘FSOUND_Close’ [-Wimplicit-function-declaration]
   18 |        FSOUND_Close();
      |        ^~~~~~~~~~~~

I have no idea what to do and i don’t know if the #include part or the gcc part is responsible for the errors.

Any idea what can i do? I have never used any library other than standard c librarys.


As far as I can tell, the issue isn’t that you haven’t included the FMOD library, but that you’re using extremely outdated API functions. All of the FSOUND-related objects and functions no longer exist.

I would recommend taking a look at the examples included with the FMOD Engine Linux installer at ./api/core/examples, specifically the “play_sound” example, which provides a simple example of playing a few sounds. I would also recommend taking a look at our Core API Reference to familiarize yourself with the API functions as they are currently.