How to set up FMOD Engine with Qt6 MinGW 64-bit

I want to try to run FMOD on Windows 10 with Qt6 MinGW 64-bit but I have a problem: undefined reference to `FMOD_System_Create'. My steps are below.

I downloaded “FMOD Engine”:

image

This is the contains of the “lib/x64” folder:

image

There are no the fmod.a file here. I tried to include “fmod.dll” like this:

INCLUDEPATH += "E:/Libs/fmod-2.2.21-mingw-64-bit/include"
LIBS += -L"E:/Libs/fmod-2.2.21-mingw-64-bit/lib/x64/fmod.dll"

But I have this error: undefined reference to `FMOD_System_Create'

I tried to use FMOD with SFML in makefile. It works without the problem:

CC = g++
INC = -I"E:\Libs\SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit\include" \
      -I"E:\Libs\box2d-2.4.1-mingw-64-bit\include" \
      -I"E:\Libs\fmod-2.2.21-mingw-64-bit\include"
LIB = -L"E:\Libs\SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit\lib" \
      -L"E:\Libs\box2d-2.4.1-mingw-64-bit\lib"
FLAGS = -c -DSFML_STATIC
 
all: main.o
    $(CC) main.o $(LIB) -static \
    "E:\Libs\fmod-2.2.21-mingw-64-bit\lib\x64\fmod.dll" \
    -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lfreetype \
    -lopengl32  -lwinmm  -lgdi32 -lbox2d -o app
 
main.o: main.cpp
    $(CC) $(FLAGS) $(INC) main.cpp

Looks like you need to add the library path like so: -L"E:\Libs\fmod-2.2.21-mingw-64-bit\lib\x64"
And instead of specifying the full path to fmod.dll on your command line (“E:\Libs\fmod-2.2.21-mingw-64-bit\lib\x64\fmod.dll”) you should use -lfmod instead.

Thank you very much! I didn’t know that I can use LIBS += -lfmod with DLLs. I thought I can use it with .a only. The absolution paths work with the problem:

INCLUDEPATH += "E:/libs/fmod-2.2.21-mingw-64-bit/include"
LIBS += -L"E:/libs/fmod-2.2.21-mingw-64-bit/lib/x64/"
LIBS += -lfmod

But when I copy the fmod-2.2.21-mingw-64-bit folder to my project in the libs folder and try to set up it with a relative path:

INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include
LIBS += $$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64
LIBS += -lfmod

I see this error:

image

It can be solved by copying fmod.dll to the Debug folder:

image

Is it possible do not copy it manually? This is very bad that you don’t have libfmod.a for x64:

image

There is libfmod.a for x86:

image

It seams like I cannot use the relative set up path without manual copying of fmod.dll to the Debug folder:

INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include
LIBS += $$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64
LIBS += -lfmod

But why I don’t need to copy fmod.dll to the Debug folder when I set up FMOD using the absolute set up path:

INCLUDEPATH += "E:/libs/fmod-2.2.21-mingw-64-bit/include"
LIBS += -L"E:/libs/fmod-2.2.21-mingw-64-bit/lib/x64/"
LIBS += -lfmod

This is my simple project for Qt6 MinGW 64-bit that plays the OGG audio file on Windows: play-audio-from-resources-fmod-qt6-cpp.zip (2.77 MB) You can download it and experiment with the relative set up file. There is the libs folder with FMOD 2.2.21 inside of the project folder. I want to run it without manual copying of fmod.dll to the Debug folder. You can create the libs folder on your hard drive and copy my contains of ‘libs’ folder to it to check that absolute set up path doesn’t require manual copying of fmod.dll to the Debug folder. You should to uncomment the absolute set up path and comment the relative path (don’t forget to change a name of hard drive):

play-audio-from-resources-fmod-qt6-cpp.pro:

QT += core gui widgets

CONFIG += c++17

# The absolute set up FMOD path
# Works without manual copying of fmod.dll to the Debug folder
# INCLUDEPATH += "E:/libs/fmod-2.2.21-mingw-64-bit/include"
# LIBS += -L"E:/libs/fmod-2.2.21-mingw-64-bit/lib/x64/"
# LIBS += -lfmod

# The relative set up FMOD path
# Requires manual copying of fmod.dll to the Debug folder
INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include
LIBS += $$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64
LIBS += -lfmod

# Using fmod_vc.lib
# Requires manual copying of fmod.dll to the Debug folder
# INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include
# LIBS += $$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64/fmod_vc.lib

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# Disables all the APIs deprecated before Qt 6.0.0
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000

SOURCES += \
    main.cpp \
    widget.cpp

HEADERS += \
    widget.h

RESOURCES += \
    assets.qrc

widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QtWidgets/QWidget>
#include <fmod.h>

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

private:
    FMOD_SYSTEM *m_system;
    FMOD_SOUND *m_sound;
};

#endif // WIDGET_H

widget.cpp

#include "widget.h"

#include <QtCore/QByteArray>
#include <QtCore/QFile>
#include <QtCore/QString>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    FMOD_System_Create(&m_system, FMOD_VERSION);
    FMOD_System_Init(m_system, 32, FMOD_INIT_NORMAL, 0);

    QString soundPath(":/assets/audio/overworld.ogg");
    QFile f(soundPath);
    if (!f.open(QIODevice::OpenModeFlag::ReadOnly))
    {
        qDebug() << "Faild to open the file: " << soundPath;
        return;
    }
    QByteArray soundData = f.readAll();
    f.close();

    FMOD_CREATESOUNDEXINFO* exinfo = new FMOD_CREATESOUNDEXINFO();
    exinfo->length = static_cast<unsigned int>(soundData.length());
    exinfo->cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    FMOD_System_CreateSound(m_system, soundData.data(), FMOD_OPENMEMORY, exinfo, &m_sound);

    FMOD_Sound_SetMode(m_sound, FMOD_LOOP_OFF);

    FMOD_System_PlaySound(m_system, m_sound, 0, false, 0);
}

Widget::~Widget()
{
    delete m_system;
    delete m_sound;
}

main.cpp

#include "widget.h"

#include <QtWidgets/QApplication>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    Widget w;
    w.show();
    return app.exec();
}

assets.qrc

<RCC>
    <qresource prefix="/">
        <file>assets/audio/overworld.ogg</file>
    </qresource>
</RCC>

So I want to run my app inside of Qt Creator with relative set up path (with using $$PWD instead of "E:/) because I want to distribute my examples with included libs. For example, I can post my examples (ZIPs) on the forums and people can download it and run without set up of FMOD and so on. And without manual copying of fmod.dlll to the Debug folder. For a while the "E:/ method (absolute path) works without manual copying of fmod.dll but the $$PWD method (relative path) requires to copy fmod.dll to the Debug folder. The distribution of EXE is very clear for me. Yes, of course I should distribute fmod.dll, Qt6Core.dll and so on with EXE. My question about distribution of Qt project with libs to run it very quickly in Qt Creator on another computer.

The $$PWD method (relative path) allows to include all libs to a project. I should works like this - everyone can download the project and run it without downloading requires libs and without manual copying of fmod.dll to the Debug folder:

image

It sounds like your problem is solved. On Windows you generally ship fmod.dll in the same directory as your .exe. If your .exe is being built to the “debug” directory then you need to make sure your build process copies fmod.dll there too. Can you copy it there in a build step?

It looks like you skipped this text:

But why I don’t need to copy fmod.dll to the Debug folder when I set up FMOD using the absolute set up path:

INCLUDEPATH += "E:/libs/fmod-2.2.21-mingw-64-bit/include"
LIBS += -L"E:/libs/fmod-2.2.21-mingw-64-bit/lib/x64/"
LIBS += -lfmod

I have tested many times that these settings above do NOT require copying fmod.dll to the debug directory:

image

Please, download my example play-audio-from-resources-fmod-qt6-cpp.zip to run it in Qt Creator. You will find this folder inside of my example: libs/fmod-2.2.21-mingw-64-bit:

image

Copy the libs/fmod-2.2.21-mingw-64-bit folder to your E disk and uncomment these setting in the pro file:

INCLUDEPATH += "E:/libs/fmod-2.2.21-mingw-64-bit/include"
LIBS += -L"E:/libs/fmod-2.2.21-mingw-64-bit/lib/x64/"
LIBS += -lfmod

Let me know that my example does NOT require to copy fmod.dll manually.

My question is about why I cannot use the next settings without manual copying of fmod.dll (like I can do with setting above):

INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include
LIBS += $$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64
LIBS += -lfmod

jsulm answered here that SUBDIRS can help to copy fmod.dll during the build. I didn’t try it.

@8Observer8 It looks like the library is part of your project. You could use SUBDIRS - handling dependencies - Qt Wiki project and make your main project depend on the library sub-project. In that case the libs should be copied during the build.

Sorry, but this is not an FMOD-specific issue, it’s an issue with your Qt Creator usage. I think you’ve done the right thing by creating a thread on the Qt forums - the people there will be able to help you with Qt Creator issues better than we can.

1 Like

I solved the problem with the relative paths to the library! I just added -L before $$PWD like this:

INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include
LIBS += -L$$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64
LIBS += -lfmod

Now you can download the next example and run it in Qt Creator (with MinGW 64) without necessary to set up FMOD or changing the paths in pro-file: play-audio-from-resources-fmod-qt6-cpp.zip (2.51 MB)