Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - The Joyful Programmer

Pages: [1]
1
Audio / SFML Audio not statically linking - Observation
« on: July 04, 2024, 08:44:22 pm »
This is an observation, not a request for help.

CURRENT SETUP:
  • Windows 11 - 64-Bit
  • Compilers (i.e. GCC v14.1.0) and Libraries (i.e. SFML v2.6.1) are installed through MSYS2 (currently up to date)
  • Using the CODE::BLOCKS IDE v20.03 (because I help beginners)
CURRENT COMPILER SETTINGS:
These settings are set in the "Project build options", not the "Global compiler settings" in Code::Blocks.
  • [-m64]        Target x86_64
  • [-Wall]       Enable all common compiler warnings
  • [-O2]         Optimize for speed
  • [-s]          Strip all symbols from binary
  • [-std=c++23]  Follow the C++ language standard 23
#DEFINES:
  • SFML_STATIC
LINKER SETTINGS:
  • sfml-system-s
  • sfml-audio.dll (Could not get the SFML-AUDIO-S library to work)
  • winmm
SEARCH DIRECTORIES:
  • COMPILER:  C:\msys64\ucrt64\include
  • Linker:  C:\msys64\ucrt64\lib
This all works great on my computer, but when I move it to another Windows 11 machine, it requires the following DLL files to be in the same directory/folder as the executable:
  • libFLAC.dll
  • libgcc_s_seh-1.dll
  • libogg-0.dll
  • libopenal-1.dll
  • libsfml-audio-2.dll
  • libsfml-system-2.dll
  • libstdc++-6.dll
  • libvorbis-0.dll
  • libvorbisenc-2.dll
  • libvorbisfile-3.dll
  • libwinpthread-1.dll
All these DLL files can be found in the C:\msys64\ucrt64\bin directory (if that is where MSYS2 was installed).

I have tried using [-static], [-static-libstdc++], and [-static] + [-static-libstdc++], but all the DLLs above are still required. As such, I removed [-static] and [-static-libstdc++] to keep the executable file size down to a bare minimum.

In the following source code, I used a modified version of the "PlayMusic()" function provided in the SFML "sound" example.

#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <string>
#include <iostream>


void
playMusic(const std::string& filename)
{
    const float FrameSpeed = 1.0f / 60.0f;

    sf::Music music;
    if (!music.openFromFile(filename)) return;

    std::cout << filename << ":\n"
              << " " << music.getDuration().asSeconds() << " seconds\n"
              << " " << music.getSampleRate()           << " samples / sec\n"
              << " " << music.getChannelCount()         << " channels\n";

    music.play();

    while (music.getStatus() == sf::Music::Playing)
    {
        sf::sleep(sf::seconds(FrameSpeed));

        std::cout << "\rPlaying... "
                  << music.getPlayingOffset().asSeconds()
                  << " sec        "
                  << std::flush;
    }

    std::cout << "\n\n";
}


int
main() {

    playMusic("music/Moonlight Hall.mp3");

}

 

No MINGW or VISUAL STUDIO was used or harmed in the making of the test demo or this post.

Pages: [1]
anything