Using OpenAL in Windows, LNK2001 error (unresolved external symbol)

I’m trying to port the OpenAL module to work in windows (x64) with Unreal Editor, to use OpenAL instead of XAudio in Windows. To do this, I first changed the build script (UnrealEd.Build.cs) line from:

if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
{PublicDependencyModuleNames.Add("XAudio2");

to

{PublicDependencyModuleNames.Add("ALAudio");

which causes the ALAudio project to attempt to compile. I then had to change some lines in ALAudioBuffer.cpp due to differences between how gcc and VC++'13 handle casts from enumerated types, but I was able to get the code to compile.

In order to link to the proper OpenAL (in my case, OpenAL Soft) libraries, I added the following lines to the OpenAL build script (under ThirdParty\OpenAL\OpenAL.build.cs).

if (Target.Platform == UnrealTargetPlatform.Win64){
        // add libs for OpenAL 
        PublicAdditionalLibraries.Add(OpenALPath + "lib/Win64/common.lib");
        PublicAdditionalLibraries.Add(OpenALPath + "lib/Win64/OpenAL32.lib");
}

This resolves most of the link errors that I would normally get (which indicates to me that it is properly linking most of the openAL functions). Note that I’ve compiled files common.lib and OpenAL32.lib myself from the OpenAL Soft source using VS’13, so the libraries should be compatible with VS’13. I’ve also placed the library files in the proper directory (I’m using C:\dev\UnrealEngine-release\Engine\Source\ThirdParty\OpenAL\1.15.1\lib\Win64). However, I still get the linker error:

1>     Creating library C:\dev\UnrealEngine-release\Engine\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-ALAudio.lib and object C:\dev\UnrealEngine-release\Engine\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-ALAudio.exp
1>Module.ALAudio.cpp.obj : error LNK2001: unresolved external symbol "struct FThreadSafeStaticStat<struct FStat_STAT_AudioResourceCreationTime> StatPtr_STAT_AudioResourceCreationTime" (?StatPtr_STAT_AudioResourceCreationTime@@3U?$FThreadSafeStaticStat@UFStat_STAT_AudioResourceCreationTime@@@@A)
1>C:\dev\UnrealEngine-release\Engine\Binaries\Win64\UE4Editor-ALAudio.dll : fatal error LNK1120: 1 unresolved externals

I’m not sure how to interpret this linker error, as I’m using the correct (AFAIK) headers and libraries for VS’13 (since I’ve built them myself).

Any help with this would be appreciated.

As far as I can see the ALAudio module is for Linux and HTML5 only.

When you use
PublicDependencyModuleNames.Add(“ALAudio”);
the UBT is trying to build a registered module which in this case is inside the Runtime/Linux and Runtime/HTML5 directories. I’m not sure if UBT is using those directories when building Win64.

To make it work on Windows you should make a module in Source/Runtime/Windows that implements the OpenAL or try to move it to the Source/Runtime. You can look at libcurl how it is done.

The interesting thing is that I can’t find an ALAudio.cpp file :confused:

I don’t have full sources on this computer, but I know you went to the quite deep engine stuff here :wink:

Turns out the problem is that how some performance metrics were done on Linux is different than on Windows, so the reference to AudioResourceCreationTime doesn’t exist on the windows platform. I just removed that reference, it builds fine, and even runs and instantiates an OpenAL device “Generic Software”, but there’s no sound yet. It’s close though, I bet I can figure it out with some more debugging.

I did some more research and was able to get OpenAL working correctly under Windows. The key to getting it to link properly is to comment out the line:

SCOPE_CYCLE_COUNTER( STAT_AudioResourceCreationTime );

which in the file ALAudioBuffer.cpp. This relates to some performance metric mechanism which doesn’t seem to work the same way under Windows. I also had to modify the file ALAudioDevice.cpp and add PLATFORM_WINDOWS to the following pre-processor #ifs, to make OpenAL actually register itself as the audio context: e.g:

#if PLATFORM_HTML5_WIN32 || PLATFORM_LINUX || PLATFORM_WINDOWS
	SoundContext = alcCreateContext( HardwareDevice, Caps );

After these changes (and the above ones I’ve already stated in my question), OpenAL seems to work fine under Windows. Of course, you have to ensure that it uses ALAudio as the audio module, by editing WindowsEngine.ini:

[Audio]
AudioDeviceModuleName=ALAudio

Zuofu, can I download files that you changed for OpenAL use?
And will it work with Rapture3D OpenAL?
Thanks! :slight_smile: