1

I am using Code::Blocks on 64bit Windows 7, MinGW 4.7.1.

I'm trying to get SFML 2.1 to work with MingW in codeblocks, but it's causing problems.

when i try to compile i get these errors:

undefined reference to _imp___ZN2sf6StringC1EPKcRKSt6locale

undefined reference to _imp___ZN2sf9VideoModeC1Ejjj

...

I'm linking the following libraries:

  • sfml-graphics
  • sfml-window
  • sfml-system

What am I doing wrong? The errors say undefined reference, but I have already follow these instructions step by step.

1 Answer 1

1

When trying to link the static version of the library, you'll essentially have to use the static version of the headers as well (otherwise you're essentially looking for the references at the wrong place (more specifically: with the wrong format/decoration)).

As such, when linking the static version, always make sure that SFML_STATIC is defined before you include any SFML header.

Also, make sure to link the static version of the libraries (with a -s suffixed).


Static SFML

  • Define SFML_STATIC.
  • Link to sfml-system-s, sfml-window-s, sfml-graphics-s, etc. (or their debug versions).

Dynamic SFML

  • Do not define SFML_STATIC.
  • Link to * sfml-system*, sfml-window, sfml-graphics, etc. (or their debug versions).
Sign up to request clarification or add additional context in comments.

4 Comments

this time I defined the SFML_STATIC before SFML header, and changed link to: sfml-window-s, sfml-graphics-s,sfml-system-s, but still same error. By the way, i have already copied the SFML DLLs to the directory where my compiled executable is before i use sfml-system, etc to link.
You won't need the dll files if you're linking the static version. Are you sure you know what you're doing? :)
thx, to be honest, i don't know the difference between static version and dynamic version, can you recommend me a good book about these, i want to make a systematic study for it. thx a lot.
Libraries are essentially code collections so code can be reused. If you're using a static library, then only the code portions you actually use are copied into your final binary file (at link time). On the other hand, if you're using a dynamic library, then the code remains in the library file (e.g. dll files under Windows). Those are core c/c++ concepts and you should be able to find more about this in pretty much any book about the language(s).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.