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?
#help setting up SFML on code::blocks
1 messages · Page 1 of 1 (latest)
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.
Maybe you are using the library incorrectly.
Your program built successfully, it's encountering an error during runtime.
yes it is
console says Process returned -1073741511 (0xC0000139)
So maybe would help to show some code.
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;
} ```
Copy the SFML libraries to the same directory where you have your executable
the .dll files? i did
Hmm. Maybe the version of SFML you've downloaded is somehow incompatible with your mingw?
could be the case
because i haven't verified that
I'd install both from msys2, that's guaranteed to be compatible
i'd have to reinstall minGW right
Yeah, msys2 installs its own mingw
so how do i delete the old one
Uninstall or remove apps and programs in the Settings app.
If that doesn't work, find the installation directory and delete it (might be C:\MinGW or something like that)
ok i'll try later
By default on Code::Blocks, the working directory is not where the executable is, it's the project’s directory.
Either move the DLL files there, or change it in the Project > Properties > Build Target > Execution working dir.
it's not a working directory issue
otherwise it would work if i run executable from file explorer
but that's not the case
The DLL is successfully loaded there.
Again this is a runtime error from that library.
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
Working directory isn't where Windows searches for DLLs, I believe
What did you do to install it?
i run pacman -S mingw-w64-ucrt-x86_64-gcc inside mingw64.exe
This looks like Windows' own error message
Ok, good. It doesn't matter inside which msys2 terminal you run this
oh ok
You also want pacman -S mingw-w64-ucrt-x86_64-sfml for SFML
i'll try only with new mingw first and if it still doesnt work i'll get new SFML
Which is reporting std::bad_array_new_length there.
It's in C:\msys64\ucrt64\bin 🙂
just the executable will work?
alright this time a diffrent error
so that means new SFML time
so where's the sfml @grizzled elk
Go to C:\msys64\ucrt64\bin, and copy those DLLs: libgcc, libstdc++, libwinpthreads, SFML
Into the directory where CB generates the .exe
there's no SFML.dll
also wouldn't this mean I have to link those in the project settings
You're already linking them, don't you?
Or you'd get linking errors
no i sent my linking setup with the post
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
so change search directories?
i dont understand what you mean here
Yes
From C:\msys64\ucrt64\bin, copy libsfml-graphics.dll, and same for "window" and "system"
Copy them to directory where you have your .exe
oh ok they're not called libsfml
Mkay
sfml-...-2
That's ok
oh wait nvm
i was supposed to do the opposite
now im getting this when compiling
what the hell is -lsfml
-l... means link library ...
CB is prepending -l to the libraries you give it
Give me a moment...
wait so it's expecting sfml-... instead of sfml-...-2 now?
Alright, let me try this myself
ok
Do you know how to compile manually in the terminal?
nope
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
how do i write spaces in the directory
-bash: g++: command not found
Ah crap, you need MSYS2 UCRT64, not MSYS2 MINGW64
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
a.exe: not found
You're in the wrong directory, use cd
where do i go with cd
Same as before
oh
Where you have your source code, and now the a.exe as well
i wish ctrl + v worked in this console
I think Shift+Insert works here
it said this
why does it want this much
libgcc, libwinpthreads, libstdc++ are parts of the standard library
Everything else is additional libraries that sfml pulls in
shouldn't this only be on static linking
Wdym?
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
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
i wanted static but resorted to dynamic because it looked a lot simplier
They both aren't too hard
Dynamic is usually better because it lets your users update the libraries themselves if they need to
Yeah
Before you copy, if you try to run a.exe from the file explorer, it likely won't work
do i throw out all the current dlls i currently have too
it works lol
Did you add your compiler to PATH or something?
Then I guess you didn't 🤔
If it works, it works
Now to figure out how to do it in CB
Where did you copy to? Sure it's the right directory?
sfml libraries not found
into release folder
Can you screenshot the contents?
If you double-click the .exe in that folder, do you get the same error?
i dont get an exe
the compiler wont make one
Is it this error?
yes
Can you screenshot your compiler settings in CB?
which tab?
Hmm. No, those two should be empty
ye
Uhh. Do you know where exactly?
Um, how did you copy it?
i copied gcc.exe from msys bin and pasted it here
Lol
Don't do that
The compiler isn't a just single file that can work in isolation, leave it where it was
oh yeah i was confused about the rest of MinGW folder
yeah i know where that is
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
guess i'll just redirect it to msys bin instead of being stubborn
Everything else same as on the screenshot
didnt fix the error
Show the screenshot of the new settings
And paste the contents of the build log tab
Drop the \bin at the end of the first one
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))
Hmmm
This looks like there's some other version of mingw you have installed, that gets used instead of msys2
wtf
Give me a sec...
i uninstalled old version by simply deleting the MinGW folder
There's gotta be another one somewhere
maybe from my failed attempt to migrate to vsc
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
oh yeah i remember stuff like this from vsc
^ 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
Yeah, it worked for me in english...
No, ucrt64
yeah right
screenshot was made for a different tutorial...
is it fine if apply didnt light up when i exited those subwindows
Reopen them, see if your changes are still there
yeah
Make sure you press ok and not cancel when closing them, or they won't save anything
now what
yeah
Okay, can you open the "command prompt", type echo %PATH% and screenshot everything that it prints?
Let's see if you set it correctly
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;
The heck
CB is acting up...
yeah
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
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
nope it reinstalled
nope still nothing nothing changes
i tried restarting too
Can you screenshot the new build log just in case?
Also where exactly do you click to open those settings?
Settings into Compiler...
Ah okay, at least the full path is reflected in the log, so you're changing settings in the right place
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
Wait, maybe it's the -static thing. Remove -static -static-libgcc -static-libstdc++
I dunno, but you've added it somewhere because it shows up in the log
Check both CB settings, and project settings
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
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 😛
changing the code it also works
Good 👍
yeah i wanna do that whenever i wanna share my programs with other people, but for now i'm just getting into learning this stuff
there's one thing that still concerns me though
what if i wanna add audio or network from sfml later on 💀
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
Now about this. If you keep using dynamic linking, then you just need to consult ntldd again for the new list of DLLs to copy
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 😅
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
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
You're welcome 😛
time to finally start actual coding..
@dull forge Has your question been resolved? If so, type !solved :)
!solved
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
@brisk trellis Please do not send invite links
@dull forge there is a official sfml server to ask spezific questions
thanks i'll make sure to join it
^^
send me invite in dms