I'm getting a multiple definition error when I try to compile my program in including the MiniAudio library.
Here's the skeleton of my application:
player.h
#ifndef PLAYER_H
#define PLAYER_H
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"
class Player
{
...
}
#endif
main.h
#ifndef MAIN_H
#define MAIN_H
#include "player.h"
class Application
{
...
}
#endif
player.cpp
#include "main.h"
void Application::whateverFunc()
{
...
}
I get the following errors:
player.cpp:(.text+0x7d330): multiple definition of `drwav_init_file_w'; obj/main.o:main.cpp:(.text+0x7d88e): first defined here /usr/bin/ld: obj/player.o: in function `ma_wav_init_memory(void const*, unsigned long, ma_decoding_backend_config const*, ma_allocation_callbacks const*, ma_wav*)': player.cpp:(.text+0x52c24): multiple definition of `ma_wav_init_memory(void const*, unsigned long, ma_decoding_backend_config const*, ma_allocation_callbacks const*, ma_wav*)'; obj/main.o:main.cpp:(.text+0x530e5): first defined here /usr/bin/ld: obj/player.o: in function `drwav_init_memory':
etc....
How can I fix this ?
Every time you do a:
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"
you get another copy of the definitions.
Quoth the fine manual:
If you prefer separate .h and .c files, you can find a split version of miniaudio in the extras/miniaudio_split folder. From here you can use miniaudio as a traditional .c and .h library - just add miniaudio.c to your source tree like any other source file and include miniaudio.h like a normal header.
Source https://github.com/mackron/miniaudio
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With