Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Difficulty in getting SFML to work (first use) with Code::Blocks/MinGW (C++)  (Read 12031 times)

0 Members and 1 Guest are viewing this topic.

chessguy

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Greetings, all.

Longer stories short, I know C++ - sort of - but have never been able to get external libraries to work yet - and the console just isn't quite that good for making games. So, I decided to give SFML a try.

As I expected, it did not work. Quite likely my fault. Anyhow. So, I followed the tuturial on the wiki - or mabye the main site - on hot to link to it, etc with code blocks and mingw for 1.6.

In Global compiler settings, search directories, compiler I got the SFML include folder, and in linker the lib folder.

So far, so good.

Linking libraries themselves has always been my problem, it seems. SinceI have no idea how to use SFML at all, I decided to just try ti include the system library. Still in global compiler options (you could do it per project in project build options though) and then linker options (Or wherever the ability to link specific libraries is) and then the other linker options boxs, I added "-lsfml-system". I took the code on the wiki (uses some clock function) and tried to run it. The console came up, but I got an error popup, something about...

"This application has failed to start because sfml-system.dll was not found. Re-installing the application may fix the problem."

Note that I am using the toolchain exutables, etc from the minggw gcc thing on the wiki.

I tried adding several prefixes -  -d, -s, -s-d, all the same error. I also tried the SFML_DYNAMIC link, although I am not entirely certain how I will be linking them... the idea of static seems nice - just one exutable, not a folder with it, etc - but it seems dynamic is the prefered method. Ideas on that Either way, I cannot seem to get it to work.

I think I will, unless you have recomendations otherwise, try to link dynamically.

Any ideas how I can get past this?

Thanks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Copy the missing DLL where your executable will find it -- in its directory.

By the way, it is written in the tutorial:
Quote
If you linked against the dynamic versions of the SFML libraries, donc forget to copy the corresponding DLLs (sfml-system.dll in this case) to your executable's directory, or to a directory contained in the PATH environment variable.
Laurent Gomila - SFML developer

chessguy

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Ah. Your right. My origional plan was to link statically so I didn't think it mattered.

If I do it like that, it runs with no errors. And this is... is this dynamically linking? I still don't entirely get that concept. I don't think I defined SFML_DYNAMIC. Nope, I didn't.

How about this: How do you think I should try to link them? Statically sounds nice due to it being only one excutable, etc, but it seems dynamic is preferred. I think dynamic is the DLL's, anyhow. Although when I tried doing it statically it brough tup the same error, so I am a bit lost. Where do you recommend I try to use?

Thanks for your help. Much appreciated.
« Last Edit: April 10, 2012, 05:43:14 pm by chessguy »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Quote
I don't think I defined SFML_DYNAMIC. Nope, I didn't.
It is optional with gcc on Windows.

What to use really depends on your personal taste. And it doesn't really matter until you distribute your applications anyway.
Laurent Gomila - SFML developer

chessguy

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
True.

Ok. I have decided, at least for now, to try static linking.

In other linker ptions, I did -lsfml-system-s, etc. I still don't entirely understands what debug configeration means, though,  Still no defines. On the bottom of the tuturial article, I am not entirely sure what it meant by including external libraries and some extra step. Can you explain this?

Now, both with that and also using the DLL's, trying to use samples, for instance, never did anything. Say, the window sample: if I read it correctly the window should say open witht he while loop and display. I got a popup of the console window. Pong brings up an error regarding cos not being part of the std namespace, and something else I am unsure of. I think it may be related to those external audio libraries.

My attempt at static libraries refuse to run at all. An empty project with a simple main reference brings up a winmain16 error, which I don't entirely understand why it is there.

Any ideas?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Can we please try to solve one problem after the other? Your last post mixes so many problems that it is impossible to answer properly.

Describe your first/main problem quietly, with detailed explanations. And don't try to do 1000 things at the same time ;)
Laurent Gomila - SFML developer

chessguy

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Seems my programming attempts are always full of problems... hrm

Ok, so I am using SFML 1.6 with Code Blocks and minGW.

I am trying to link it statically. I have tried following the tuturial but cannot seem to make anything work.

That is about where I am right now. Also, should I assume that I should make an empty project? I figured so but it is possible it is important when GUI is considered.

I hav edownloaded the... mingw versiom mentioned on the tuturial, and it is set to using that for compiling/deugging/linking. I have also downloaded the full SDK.

Thanks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
And? What's your problem then?
Laurent Gomila - SFML developer

CJ_COIMBRA

  • Full Member
  • ***
  • Posts: 112
    • ICQ Messenger - 13077864
    • View Profile
    • http://www.cjcoimbra.com
    • Email
Maybe you could try downloading that Code:Blocks that already comes with the mingw configured so that you don't need to bother with that. Your problem might not be SFML.
CJ

chessguy

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Origionally, I did install Code::Blocks with the MinGw with it, but the tuturial article suggested whatever other version.

It has ben suggested to me that I should try version two instead. Why did it go from 1.6 to 2.0, anyhow? Hrm. Although, the process of building it looks complex so I may search around for a place where somebody already made the binaries.

After that, though, I have the same problems...

I can set it so the linker/compiler can find it, (/include, /lib). I can put the libraries I am using in the exutables directory (for me, this seems to be just the same folder it is in - can this be made easier somehow?). In other linker options, I added, say, system, as -lsfml-system. I made an empy project. Testing any code from SFML, it... does not always throw errors, but it does nothing either - just a console window popup. This was true even for the window example when had a while loop.

On another note, when I was using static, I seemed to get more errors for whatever reason - fatal errors. Not sure why. Some of htem were things regarding WinMain16, which is odd because I had a main(). Or, int main(), to be precise.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Maybe you should just wait for the 2.0-rc binaries. They'll be online this week-end, hopefully.
Laurent Gomila - SFML developer

chessguy

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
The 2 binaries are coming out in a few days?

Have you heard og Game Maker? Mabye you have. As with most games engines, it is more user friendly. IT has (at least, the way I used it), a stripped down and very friendly version of C/C++, sort of.

It is useful because it is easy to make things, such as how it goes with "rooms" sort of like D&D level design. However, in the same way that it is useful, the same friendliness also restricts it a bit, and I want to try to make it... well, this way.

So, in my adventures, I found Code::Blocks. And, seeing as I didn't really know a thing about compilers or linkers at the time (still pretty true), I am using MinGW.

I, following tuturials, began learning C++ using the compiler. Worked, more or less. LEarned... most things. Practice will help though. However, it struck me that, you cannot really make games all that well on the console alone with no external libraries - not that I know of anyhow.

So, I tried SDL, Allegro, and now this. I seemed to be cursed in that not a single one worked for me for whatever reason. I assume it is my fault somehow but at the same time I seemed to have followed the directions.

Seeing as how SFML 1.6 seemed to sort of work but not.. work at the same time, and do to some recommendations, I think I will try SFML 2, provided I can find a build of it. MY main hope is that I can at least try to make thing using the functions, and it, eh, works.

On that note, I am a bit confused. I feel like I like the idea of a static linking where you only hae on e exutable, but it occurs to me to load images, sounds, etc you will need to send other stuff with it as well, and thus... sigh. I am just a bit confused and frustrated.

Think we can ever make it work? :) (for me)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
SFML 2.0-rc is out ;)
Laurent Gomila - SFML developer

chessguy

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Ah. Yes. I see that, and am using it now. Here is what I did.

I made a new, empty project.
I went to PRoject Properties, and made it into a GUI application (for both debug and release for that project)
I went to Project Build Options
    I went to search directories, and got the sfml include folder for compiler
    I went to search directories, and got the sfml lib folder for compiler
    I went to linker options, then other linker options, and added in this order:
-sfml-graphics
-sfml-window
-sfml-system

I used a small code concocted with some help from the HTML doc, it was like so:

#include <SFML/system.hpp>
#include <SFML/window.hpp>

int main()
{
while (!(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
//hrm
}
}

In theory, when you press up, it will close, right? I don't recall if it was isKeyPressed or getKeyPressed.. I made it using the help doc and it threw no errors once I got it right. This was off the top of my head though.

The error I get is from g++: -sfml-(whatever_module): no such file or directory.

This occurs for all three files listed in the other linker options. Ideas?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Quote
I went to search directories, and got the sfml lib folder for compiler
The lib path must be in the linker search paths.

Quote
I went to linker options, then other linker options, and added in this order:
-sfml-graphics
-sfml-window
-sfml-system
You must add either "sfml-xxx" in Libraries, or "-lsfml-xxx" in Other options.
Laurent Gomila - SFML developer

 

anything