News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

SFML Not working

Started by BL4238954, December 11, 2023, 08:48:18 PM

Previous topic - Next topic

BL4238954

Hi all,

I've been working on SFML for the past two years trying to get it working but nothing happened. Even after watching countless Youtube videos and checking posts in the forums, nothing worked.

Pls I need help

Miguel Gimenez

"Not working" is far too vague, please attach symptoms, build log and screen captures...

omlk


BL4238954

Quote from: Miguel Gimenez on December 11, 2023, 09:08:25 PM
"Not working" is far too vague, please attach symptoms, build log and screen captures...

Well, ever since I started with SFML x64bit on CodeBlocks, error like:
  undefined reference to `__imp__ZN2sf6StringClEPKcRKSt6locale'...
with build logs:
       g++.exe -LC:\Users\%username%\SFML-2.5.1\lib -o bin\Debug\sfml.exe obj\Debug\main.o   -lsfml-graphics-d -lsfml-audio-d -lsfml-network-d -lsfml-window-d -lsfml-system-d
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
obj\Debug\main.o: in function `main':
C:/Users/%username%/sfml/main.cpp:5: undefined reference to `__imp__ZN2sf6StringC1EPKcRKSt6locale'



And after folling some videos on Youtube, I later SFML-2.5.1 x32bit then this happened:
  cannot find -lsfml-graphics-d: No such file or directory...
with build logs:
  g++.exe -L"C:\Users\%username%\Documents\New folder\SFML-2.5.1-windows-gcc-7.3.0-mingw-32-bit\SFML-2.5.1\lib" -o bin\Debug\sfml.exe obj\Debug\main.o   -lsfml-graphics-d -lsfml-audio-d -lsfml-network-d -lsfml-window-d -lsfml-system-d
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Users\%username%\Documents\New folder\SFML-2.5.1-windows-gcc-7.3.0-mingw-32-bit\SFML-2.5.1\lib/libsfml-graphics-d.a when searching for -lsfml-graphics-d

At least got another error

Then after going through the forum, it said that I should change add 'lib' to the beginning of the library files and still got the same error

Miguel Gimenez

#4
The first case looks like you are mixing Visual Studio libraries with gcc objects.
In the second you are mixing 64 bit with 32 bit.

I would not use precompiled libraries, just compile SFML with the same gcc used for the main program. All C++ code that will be linked together must be compiled with the same compiler.

There is a complete tutorial for using SFML with C::B here, just remember to compile SFML with the same gcc.

nenin

Quote from: BL4238954 on December 12, 2023, 11:00:00 AM
Well, ever since I started with SFML x64bit on CodeBlocks,
Here :https://github.com/SFML/SFML/releases/download/2.6.1/SFML-2.6.1-windows-gcc-13.1.0-mingw-64-bit.zip
are DLLs, bult with WinLibs GCC MSVCRT. If you use the same compiler, you can use this package. If not, you have no options but build SFML from sources using CMAKE.
Dont mix-up MSVCRT and UCRT versions.


BL4238954

Thanks is finially works, but I have this popup

BL4238954

And yet, I added the DLL files from the bin folder to the location of the application and still got another popup:

stahta01

#8
Did you self-build SFML using the exact same compiler you are using with Code::Blocks?

If the answer is no; then you likely will never get a good build that runs.

Edit: I just ran the CB example code using MSys2 UCRT64 and it worked for me.
NOTE: MSys2 UCRT64 does not have debug versions of the libraries.

Edit2: Attached CB Project
Edit3: Project was created using CB console Wizard; and, then I modified it till it built and ran.
I copied the main.cpp and BMP from the CB scripted wizard sfml resource folder.
Edit4: More research implies sfml-main library is only needed for static build.
Edit5: Add link https://www.sfml-dev.org/tutorials/2.6/start-cb.php
Edit6: Add link to updated CB Project https://github.com/stahta01/MSys2_CodeBlocks_Projects/blob/main/sfml/demo_sfml.cbp
Edit7: Delete old attached CB Project
Edit8: Change build logs to new project.

$ pacman -Qs sfml
local/mingw-w64-ucrt-x86_64-sfml 2.6.1-1
    A simple, fast, cross-platform, and object-oriented multimedia API (mingw-w64)



-------------- Build: Debug_shared in demo_sfml (compiler: GNU GCC Compiler)---------------

g++.exe -Wall -fexceptions -g  -c H:\devel\cb_projects\test\testsfml\main.cpp -o obj\Debug\main.o
g++.exe  -o bin\Debug\testsfml.exe obj\Debug\main.o   -lsfml-window.dll -lsfml-graphics.dll -lsfml-system.dll
Output file is bin\Debug\testsfml.exe with size 366.23 KB

-------------- Build: Release_shared in demo_sfml (compiler: GNU GCC Compiler)---------------

g++.exe -Wall -fexceptions -O2  -c H:\devel\cb_projects\test\testsfml\main.cpp -o obj\Release\main.o
g++.exe  -o bin\Release\testsfml.exe obj\Release\main.o  -s  -lsfml-window.dll -lsfml-graphics.dll -lsfml-system.dll -mwindows
Output file is bin\Release\testsfml.exe with size 21.00 KB

-------------- Build: Debug_static in demo_sfml (compiler: GNU GCC Compiler)---------------

g++.exe -Wall -fexceptions -g -DSFML_STATIC  -c H:\devel\cb_projects\test\testsfml\main.cpp -o obj\Debug_static\main.o
g++.exe  -o bin\Debug_static\testsfml.exe obj\Debug_static\main.o   -lsfml-main -lsfml-window-s -lsfml-graphics-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32
Output file is bin\Debug_static\testsfml.exe with size 1.40 MB

-------------- Build: Release_static in demo_sfml (compiler: GNU GCC Compiler)---------------

g++.exe -Wall -fexceptions -O2 -DSFML_STATIC  -c H:\devel\cb_projects\test\testsfml\main.cpp -o obj\Release_static\main.o
g++.exe  -o bin\Release_static\testsfml.exe obj\Release_static\main.o   -lsfml-main -lsfml-window-s -lsfml-graphics-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 -mwindows
Output file is bin\Release_static\testsfml.exe with size 1.18 MB


Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Frank_CB

Using Nightly version 13413 with the GCC 13.1.0 compiler, I downloaded the SFML-2.6.1 Binary that uses the same compiler. After unzipping the SFML binary, I created a SFML gui project in C::B. Attempting to build a Static Release, I encountered the following failure:


-------------- Clean: Release_Static in Project1 (compiler: GNU GCC 13.1.0 Mingw64 Compiler)---------------

Cleaned "Project1 - Release_Static"

-------------- Build: Release_Static in Project1 (compiler: GNU GCC 13.1.0 Mingw64 Compiler)---------------

g++.exe -Wall -fexceptions -O2 -DSFML_STATIC -IC:\sfml-gcc\include -c C:\Sandbox1\Project1\main.cpp -o .objs\main.o
g++.exe -LC:\sfml-gcc\lib -o Project1.exe .objs\main.o   -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lsfml-main -lopengl32 -lwinmm -lgdi32 -mwindows
C:/Mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\sfml-gcc\lib/libsfml-system-s.a(Err.cpp.obj):Err.cpp:(.rdata+0x80): undefined reference to `std::basic_streambuf<char, std::char_traits<char> >::seekpos(std::fpos<int>, std::_Ios_Openmode)'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 5 second(s))
2 error(s), 0 warning(s) (0 minute(s), 5 second(s))



Any ideas of what's causing the error?

stahta01

#10
static build requires more libs to be added as documented in the link I posted.

Edit: Also, under MinGW GCC the library order matters.

Edit2: I tried changing the order to match Frank's and did not see a build error; my guess is the CB compiler does not match the library build compiler.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Miguel Gimenez

The compiler comes in two flavours, MSVCRT and UCRT. They are not compatible.