#help setting up SFML on code::blocks

1 messages · Page 1 of 1 (latest)

dull forge
#

I am trying to set up SFML on code::blocks and linking the libraries dynamically, no matter what I do I get these 2 identical errors shown on images. My search directories are correctly linked. How can I fix this pls help?

uneven galleonBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

umbral owl
#

Maybe you are using the library incorrectly.

#

Your program built successfully, it's encountering an error during runtime.

dull forge
#

console says Process returned -1073741511 (0xC0000139)

umbral owl
dull forge
#

i am using the example code from their website

#

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }
    return 0;
}  ```
grizzled elk
#

Copy the SFML libraries to the same directory where you have your executable

grizzled elk
#

Hmm. Maybe the version of SFML you've downloaded is somehow incompatible with your mingw?

dull forge
#

could be the case

grizzled elk
dull forge
#

because i haven't verified that

grizzled elk
#

I'd install both from msys2, that's guaranteed to be compatible

dull forge
#

i'd have to reinstall minGW right

grizzled elk
#

Yeah, msys2 installs its own mingw

dull forge
#

so how do i delete the old one

grizzled elk
#

If that doesn't work, find the installation directory and delete it (might be C:\MinGW or something like that)

dull forge
#

ok i'll try later

surreal hare
dull forge
#

otherwise it would work if i run executable from file explorer

#

but that's not the case

umbral owl
#

Again this is a runtime error from that library.

dull forge
#

i got msys64 now

#

what do i run in this folder

#

mingw64.exe?

#

i managed to install the mingw but where the fuck is it now

grizzled elk
grizzled elk
dull forge
grizzled elk
grizzled elk
dull forge
#

oh ok

grizzled elk
#

You also want pacman -S mingw-w64-ucrt-x86_64-sfml for SFML

dull forge
#

i'll try only with new mingw first and if it still doesnt work i'll get new SFML

umbral owl
dull forge
#

now what

#

where is my mingw

grizzled elk
#

It's in C:\msys64\ucrt64\bin 🙂

dull forge
#

uhh im confused

#

i need the MinGW folder inside of codeblocks folder

grizzled elk
#

Go to codeblocks compiler settings

#

And point it to the newly installed one

dull forge
#

just the executable will work?

#

alright this time a diffrent error

#

so that means new SFML time

#

so where's the sfml @grizzled elk

grizzled elk
#

Go to C:\msys64\ucrt64\bin, and copy those DLLs: libgcc, libstdc++, libwinpthreads, SFML

#

Into the directory where CB generates the .exe

dull forge
#

also wouldn't this mean I have to link those in the project settings

grizzled elk
#

Or you'd get linking errors

dull forge
grizzled elk
#

Then copy libsfml-graphics-....dll, and same for the other two

#

Unsure how exactly they're called

#

And make sure CB searches for libraries in C:\msys64\ucrt64\lib

#

And doesn't search the copy of SFML you've downloaded

dull forge
dull forge
grizzled elk
grizzled elk
#

Copy them to directory where you have your .exe

dull forge
#

oh ok they're not called libsfml

grizzled elk
#

Mkay

dull forge
#

sfml-...-2

grizzled elk
#

That's ok

dull forge
#

oh wait nvm

#

i was supposed to do the opposite

#

now im getting this when compiling

#

what the hell is -lsfml

grizzled elk
#

-l... means link library ...

#

CB is prepending -l to the libraries you give it

#

Give me a moment...

dull forge
#

wait so it's expecting sfml-... instead of sfml-...-2 now?

grizzled elk
#

Alright, let me try this myself

dull forge
#

ok

grizzled elk
#

Do you know how to compile manually in the terminal?

dull forge
#

nope

grizzled elk
#

Open MSYS2 MINGW64 in the start menu

#

In the terminal that opens, you need to go to the directory where you have your source code, using cd. E.g. cd 'C:\path\to\my\project'

#

Then run g++ my_source.cpp -lsfml-graphics -lsfml-window -lsfml-system

#

If this works, then do ./a.exe to run the result

#

Once compiling in the terminal works, we'll try to figure out how to make CB do the same thing

dull forge
grizzled elk
#

Just as spaces

#

But in general spaces are a bad idea, some tools choke on them

dull forge
grizzled elk
#

Ah crap, you need MSYS2 UCRT64, not MSYS2 MINGW64

dull forge
#

holy shit it worked

grizzled elk
#

Alright, now to do the same thing in CB...

#

First, can you please do pacman -S mingw-w64-ucrt-x86_64-ntldd. This will install the program called ntldd, which tells you which DLLs exactly you need to copy

#

Once that's installed, run ntldd -R a.exe | grep ucrt64. That should give you the list of DLLs

grizzled elk
#

Uhm

#

Can you screenshot what you see?

grizzled elk
#

You're in the wrong directory, use cd

dull forge
#

where do i go with cd

grizzled elk
#

Same as before

dull forge
#

oh

grizzled elk
#

Where you have your source code, and now the a.exe as well

dull forge
#

i wish ctrl + v worked in this console

grizzled elk
#

I think Shift+Insert works here

dull forge
#

it said this

grizzled elk
#

Oof, that's a lot

#

I guess you need to copy all those

dull forge
#

why does it want this much

grizzled elk
#

libgcc, libwinpthreads, libstdc++ are parts of the standard library

#

Everything else is additional libraries that sfml pulls in

dull forge
#

shouldn't this only be on static linking

grizzled elk
#

Wdym?

dull forge
#

like when linking the libraries you can do dynamic or static

#

dynamic requires the dlls for program to run but static has all dlls written into the executable

grizzled elk
#

So yeah, if you linked statically, you'd need to specify all those in the compiler flags, instead of just sfml. Because static libraries don't pull their dependencies automatically

dull forge
#

i wanted static but resorted to dynamic because it looked a lot simplier

grizzled elk
#

They both aren't too hard

#

Dynamic is usually better because it lets your users update the libraries themselves if they need to

dull forge
#

anyways i gotta copy all those dlls from ucrt64 into where the executable is

#

right?

grizzled elk
#

Yeah

#

Before you copy, if you try to run a.exe from the file explorer, it likely won't work

dull forge
#

do i throw out all the current dlls i currently have too

grizzled elk
#

Did you add your compiler to PATH or something?

dull forge
#

huh

#

idk what that even means

grizzled elk
#

Then I guess you didn't 🤔

#

If it works, it works

#

Now to figure out how to do it in CB

dull forge
#

copying..

#

done

grizzled elk
#

Okay

#

So if you run it in CB, do you still get the same error?

grizzled elk
#

Where did you copy to? Sure it's the right directory?

dull forge
#

sfml libraries not found

dull forge
grizzled elk
#

Can you screenshot the contents?

#

If you double-click the .exe in that folder, do you get the same error?

dull forge
#

the compiler wont make one

grizzled elk
dull forge
#

yes

grizzled elk
#

Can you screenshot your compiler settings in CB?

dull forge
grizzled elk
#

I don't remember 😛

#

Where you set the compiler path

dull forge
#

and linker stayed the same

grizzled elk
#

Hmm. No, those two should be empty

dull forge
#

its not running the compiler inside of this folder though

#

i placed it somewhere else

grizzled elk
#

Placed what?

#

The compiler?

dull forge
#

ye

grizzled elk
#

Uhh. Do you know where exactly?

dull forge
#

ofc

#

C:\Program Files\CodeBlocks\MinGW\bin

grizzled elk
#

Um, how did you copy it?

dull forge
#

i copied gcc.exe from msys bin and pasted it here

grizzled elk
#

Lol

#

Don't do that

#

The compiler isn't a just single file that can work in isolation, leave it where it was

dull forge
#

oh yeah i was confused about the rest of MinGW folder

grizzled elk
#

You want to find those settings

dull forge
#

yeah i know where that is

grizzled elk
#

Okay. So at the top you specify C:\msys64\ucrt64. Below that, C compiler = gcc.exe, C++ compiler = g++.exe, linker for dynamic libs = g++.exe

dull forge
#

guess i'll just redirect it to msys bin instead of being stubborn

grizzled elk
#

Everything else same as on the screenshot

dull forge
#

didnt fix the error

grizzled elk
#

Show the screenshot of the new settings

#

And paste the contents of the build log tab

dull forge
grizzled elk
#

Drop the \bin at the end of the first one

dull forge
#

g++.exe -LC:\msys64\ucrt64\bin -o Release\SFML_learning_1.exe Release\main.o  -s -static-libstdc++ -static-libgcc -static  -lsfml-graphics -lsfml-window -lsfml-system
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsfml-graphics: No such file or directory
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsfml-window: No such file or directory
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsfml-system: No such file or directory
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
4 error(s), 0 warning(s) (0 minute(s), 0 second(s))
grizzled elk
#

Hmmm

#

This looks like there's some other version of mingw you have installed, that gets used instead of msys2

dull forge
#

wtf

grizzled elk
#

Give me a sec...

dull forge
#

i uninstalled old version by simply deleting the MinGW folder

grizzled elk
#

There's gotta be another one somewhere

dull forge
#

maybe from my failed attempt to migrate to vsc

grizzled elk
#

Go to the windows settings, type env in the search box, choose Edit the system environment variables, then click environment variables...

#

You'll have two PATH settings, look in them for any mingws you might have installed

dull forge
#

oh yeah i remember stuff like this from vsc

grizzled elk
#

^ This is how you want it to look like at the end. In the second path, the first entry should be C:\msys64\ucrt64\bin

dull forge
#

also you sure it's env

#

it doesn't work

#

prob because polish version

#

so annoying

grizzled elk
#

Yeah, it worked for me in english...

dull forge
#

found it tho

#

also clang64 in the variable?

grizzled elk
#

No, ucrt64

dull forge
#

yeah right

grizzled elk
#

screenshot was made for a different tutorial...

dull forge
#

is it fine if apply didnt light up when i exited those subwindows

grizzled elk
#

Reopen them, see if your changes are still there

dull forge
#

yeah

grizzled elk
#

Make sure you press ok and not cancel when closing them, or they won't save anything

dull forge
#

now what

grizzled elk
#

Now stuff should just work, even without copying the dlls

#

Try it

dull forge
#

build log still uses this other version

grizzled elk
#

Can you show me the build log again?

#

Still the same?

dull forge
#

yeah

grizzled elk
#

Okay, can you open the "command prompt", type echo %PATH% and screenshot everything that it prints?

#

Let's see if you set it correctly

dull forge
# grizzled elk Okay, can you open the "command prompt", type `echo %PATH%` and screenshot every...

C:\msys64\ucrt64\bin;C:\Program Files (x86)\Common Files\Oracle\Java\java8path;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Python312\Scripts\;C:\Python312\;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Users\Filip\AppData\Local\Microsoft\WindowsApps;C:\Users\Filip\.dotnet\tools;C:\Users\Filip\AppData\Roaming\npm;C:\Users\Filip\AppData\Local\Programs\Microsoft VS Code\bin;C:\msys64\ucrt64\bin;

grizzled elk
#

This looks good

#

Restart CB. It probably doesn't see the updated PATH until that

dull forge
#

valid

#

nope still fucking same

grizzled elk
#

The heck

dull forge
grizzled elk
#

CB is acting up...

dull forge
#

yeah

grizzled elk
#

Try going to CB settings again, and instead of g++.exe type the full path: C:\msys64\ucrt64\bin\g++.exe, and same on every other line

dull forge
#

makes sense

#

hold up this maybe is the issue?

grizzled elk
#

Not sure

#

Run pacman -S mingw-w64-ucrt-x86_64-make to install mingw32-make in msys2

#

Maybe it's missing in msys2, so CB finds one somewhere else, and it acts up

dull forge
#

nope it reinstalled

grizzled elk
#

Hmm

#

So did specifying the full path change anything?

dull forge
#

i tried restarting too

grizzled elk
#

Can you screenshot the new build log just in case?

#

Also where exactly do you click to open those settings?

dull forge
dull forge
grizzled elk
#

Ah okay, at least the full path is reflected in the log, so you're changing settings in the right place

dull forge
#

wait wait i changed a line in my code to see if something new will happen and theres a new line in the build log

#

still failed though

grizzled elk
#

Wait, maybe it's the -static thing. Remove -static -static-libgcc -static-libstdc++

dull forge
#

where do i remove -static

#

dll names?

#

no its not there

grizzled elk
#

I dunno, but you've added it somewhere because it shows up in the log

#

Check both CB settings, and project settings

dull forge
#

oh right

#

i have it enabled so that i could run exes from file explorer

#

or else it would show missing dll on run

#

holy crap it worked

#

i turned it off

grizzled elk
#

Yeah, those problems shouldn't happen now that you've set the PATH

#

Another option is to statically link everything including SFML, but let's leave that for another time 😛

dull forge
#

changing the code it also works

grizzled elk
#

Good 👍

dull forge
#

there's one thing that still concerns me though

#

what if i wanna add audio or network from sfml later on 💀

grizzled elk
#

Okay, about static linking. If you open MSYS2 UCRT64 again and type pkgconf --libs --cflags --static sfml-graphics sfml-system sfml-window, it should tell you all the flags you need for correct static linking

#

Add -static to what it prints. You don't need -static-libgcc nor -static-libstdc++, because -static already enables those two

#

You might need to install pkgconf in msys2 using pacman -S mingw-w64-ucrt-x86_64-pkgconf if its missing. It's a helpful program that tells you the correct compiler flags to use libraries

grizzled elk
dull forge
#

do you wanna add to friend list so that I can reach out to you when I have further questions?

#

and I'll show you what I'm cooking with the sfml we just tirelessly installed too 😅

grizzled elk
#

And if you switch to static linking, you run pkgconf with all those new libs to get the right flags for them

#

Sure, it's always nice to see some screenshots

#

But I don't really wanna answer programming questions in DMs. You can ask here and perhaps ping me

dull forge
#

alright

#

holy 277 messages in this thread

#

anyways thank you so much man for helping me and being patient till the end

#

I was expecting you to leave halfway through lol

grizzled elk
#

You're welcome 😛

dull forge
#

time to finally start actual coding..

uneven galleonBOT
#

@dull forge Has your question been resolved? If so, type !solved :)

dull forge
#

!solved

uneven galleonBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

uneven galleonBOT
#

@brisk trellis Please do not send invite links

brisk trellis
#

@dull forge there is a official sfml server to ask spezific questions

dull forge
brisk trellis
#

^^

dull forge
#

send me invite in dms