godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

Can't use AudioServer in GDExtension due to unresolved external symbol AudioEffectInstance::_process(...)

Open ComradeNixco opened this issue 3 years ago • 1 comments

When I try to build a dll without a reference to AudioServer, it builds correctly. But when I try to use the AudioServer, it refuses to build with this error:

FAILED: ../bin/win64/GameCore.windows.debug.x86_64.dll ../bin/win64/GameCore.windows.debug.x86_64.lib 
cmd.exe /C "cd . && C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\222.3345.126\bin\cmake\win\bin\cmake.exe -E vs_link_dll --intdir=CMakeFiles\SpaceFarer_GameCore.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x86\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x86\mt.exe --manifests  -- C:\PROGRA~2\MICROS~4\2022\BUILDT~1\VC\Tools\MSVC\1432~1.313\bin\Hostx86\x64\link.exe /nologo CMakeFiles\SpaceFarer_GameCore.dir\src\nodes\audio_manager.cpp.obj CMakeFiles\SpaceFarer_GameCore.dir\src\register_types.cpp.obj  /out:..\bin\win64\GameCore.windows.debug.x86_64.dll /implib:..\bin\win64\GameCore.windows.debug.x86_64.lib /pdb:..\bin\win64\GameCore.windows.debug.x86_64.pdb /dll /version:0.0 /machine:x64 /debug /INCREMENTAL -LIBPATH:D:\Projects\Xaita\SpaceFarer\extensions\game_core\..\godot_cpp\godot_cpp\lib libgodot-cpp.windows.debug.x86_64.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib  && cd ."
LINK Pass 1: command "C:\PROGRA~2\MICROS~4\2022\BUILDT~1\VC\Tools\MSVC\1432~1.313\bin\Hostx86\x64\link.exe /nologo CMakeFiles\SpaceFarer_GameCore.dir\src\nodes\audio_manager.cpp.obj CMakeFiles\SpaceFarer_GameCore.dir\src\register_types.cpp.obj /out:..\bin\win64\GameCore.windows.debug.x86_64.dll /implib:..\bin\win64\GameCore.windows.debug.x86_64.lib /pdb:..\bin\win64\GameCore.windows.debug.x86_64.pdb /dll /version:0.0 /machine:x64 /debug /INCREMENTAL -LIBPATH:D:\Projects\Xaita\SpaceFarer\extensions\game_core\..\godot_cpp\godot_cpp\lib libgodot-cpp.windows.debug.x86_64.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\SpaceFarer_GameCore.dir/intermediate.manifest CMakeFiles\SpaceFarer_GameCore.dir/manifest.res" failed (exit code 1120) with the following output:
   Creating library ..\bin\win64\GameCore.windows.debug.x86_64.lib and object ..\bin\win64\GameCore.windows.debug.x86_64.exp
libgodot-cpp.windows.debug.x86_64.lib(audio_server.windows.debug.x86_64.obj) : error LNK2001: unresolved external symbol "public: virtual void __cdecl godot::AudioEffectInstance::_process(void const *,class godot::AudioFrame *,__int64)" (?_process@AudioEffectInstance@godot@@UEAAXPEBXPEAVAudioFrame@2@_J@Z)
..\bin\win64\GameCore.windows.debug.x86_64.dll : fatal error LNK1120: 1 unresolved externals
ninja: build stopped: subcommand failed.

Example code:

#include "audio_manager.h"

#include <godot_cpp/classes/audio_server.hpp>
#include <godot_cpp/variant/utility_functions.hpp>


using namespace game_core::nodes;
using namespace godot;

AudioManager::AudioManager() : m_audioBusIndexesMap{ } {
}

void AudioManager::_bind_methods() {
    // GetVolumes
    {
        MethodInfo mi;
        mi.name = "GetVolumes";
        ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "GetVolumes", &AudioManager::GetVolumes, mi);
    }
}

void AudioManager::_ready() {
    Node::_ready();

    // Find and fill default audio bus layout's buses names
    const AudioServer* audioServer = AudioServer::get_singleton();
    UtilityFunctions::print("Initializing audio manager...");
    for (int i = 0; i < audioServer->get_bus_count(); ++i) {
        m_audioBusIndexesMap.emplace(audioServer->get_bus_name(i), i);
    }
    UtilityFunctions::print("...done");
}

Dictionary AudioManager::GetVolumes(const Variant** p_args, GDNativeInt p_argCount, GDNativeCallError& p_error) {
    int i = 0;
    if (p_argCount <= 0) {
    }

    return Dictionary{ };
}

ComradeNixco avatar Aug 13 '22 21:08 ComradeNixco

I'm using cmake with clion using MSVS's toolchain to build my extension, and normally scons should use msvs too for godot-cpp

ComradeNixco avatar Aug 14 '22 00:08 ComradeNixco

Is this happening with SCons? I had a look at audio_effect_instance.cpp which is generated, and I see an implementation of AudioEffectInstance::_process inside. Note that audio_effect_instance.cpp must be compiled, even if you dont use the class directly (and AFAIK the SCons script does). If CMake doesn't, then that's the problem.

Zylann avatar Sep 21 '22 17:09 Zylann