Author Topic: SFML Not working  (Read 2788 times)

Offline BL4238954

  • Single posting newcomer
  • *
  • Posts: 4
SFML Not working
« on: December 11, 2023, 08:48:18 pm »
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

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1605
Re: SFML Not working
« Reply #1 on: December 11, 2023, 09:08:25 pm »
"Not working" is far too vague, please attach symptoms, build log and screen captures...

Offline omlk

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: SFML Not working
« Reply #2 on: December 12, 2023, 07:00:24 am »
You read this SFML Learn?

Offline BL4238954

  • Single posting newcomer
  • *
  • Posts: 4
Re: SFML Not working
« Reply #3 on: December 12, 2023, 11:00:00 am »
"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

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1605
Re: SFML Not working
« Reply #4 on: December 12, 2023, 11:21:52 am »
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.
« Last Edit: December 12, 2023, 11:24:45 am by Miguel Gimenez »

Offline nenin

  • Almost regular
  • **
  • Posts: 227
Re: SFML Not working
« Reply #5 on: December 12, 2023, 12:36:12 pm »
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.


Offline BL4238954

  • Single posting newcomer
  • *
  • Posts: 4
Re: SFML Not working
« Reply #6 on: December 16, 2023, 09:13:31 pm »
Thanks is finially works, but I have this popup

Offline BL4238954

  • Single posting newcomer
  • *
  • Posts: 4
Re: SFML Not working
« Reply #7 on: December 16, 2023, 09:24:20 pm »
And yet, I added the DLL files from the bin folder to the location of the application and still got another popup:

Online stahta01

  • Lives here!
  • ****
  • Posts: 7625
    • My Best Post
Re: SFML Not working
« Reply #8 on: December 16, 2023, 10:18:44 pm »
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.

Code
$ 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)

Code
-------------- 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.
« Last Edit: December 19, 2023, 07:01:05 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Frank_CB

  • Almost regular
  • **
  • Posts: 148
Re: SFML Not working
« Reply #9 on: December 22, 2023, 08:41:26 pm »
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:

Code
-------------- 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?

Online stahta01

  • Lives here!
  • ****
  • Posts: 7625
    • My Best Post
Re: SFML Not working
« Reply #10 on: December 22, 2023, 09:53:15 pm »
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.
« Last Edit: December 22, 2023, 10:29:11 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1605
Re: SFML Not working
« Reply #11 on: December 22, 2023, 10:42:27 pm »
The compiler comes in two flavours, MSVCRT and UCRT. They are not compatible.