Using dr_wav in more than one module

Sorry, this is probably a simple C++ question, but I’m a bit rusty and could use some help. I’ve create a module that uses the “Dr Wav” library. It includes the library like so:

// file: my_module.cpp
#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"

I’ve added another module to my plugin and it also includes DR WAV in the same way:

// file: my_second_module.cpp
#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"

When I compile, I get an error:

multiple definition of `drwav_fopen(char const*, char const*)';

Any suggestions? Thanks!!

Just guessing here, but maybe only define DR_WAV_IMPLEMENTATION in one place? You seem go have multiple implementations… :wink:

1 Like

Put plugin-wide code (such as the dr_wav implementation include) in plugin.cpp.

1 Like

Thanks for the quick replies!

Squicky Labs solution worked. If I remove the #define DR_WAV_IMPLEMENTATION from one of the files, it compiles. @Vortico Andrew, your solution didn’t work for some reason. If I remove…

#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"

… from both module files and move it to plugin.cpp, I get an error:

src/my_module.cpp:22:2: error: ‘drwav_uint64’ does not name a type 22 | drwav_uint64 total_sample_count;

It sounds like your solution is ideal, so I’m confused on why it might not work.

Oh, nevermind! Here’s what’s working for me:

plugin.cpp:

#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"

#include "plugin.hpp"

(etc...

my_module.cpp:

#include "plugin.hpp"
#include "osdialog.h"
#include "dr_wav.h"
#include <vector>
#include "cmath"

my_other_module.cpp:

#include "plugin.hpp"
#include "osdialog.h"
#include "dr_wav.h"
#include <vector>
#include "cmath"

This seems to work. Thanks!

1 Like