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:
These settings are set in the "Project build options", not the "Global compiler settings" in Code::Blocks.
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.
No MINGW or VISUAL STUDIO was used or harmed in the making of the test demo or this post.
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)
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
- SFML_STATIC
- sfml-system-s
- sfml-audio.dll (Could not get the SFML-AUDIO-S library to work)
- winmm
- COMPILER: C:\msys64\ucrt64\include
- Linker: C:\msys64\ucrt64\lib
- 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
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");
}
#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.