Important: Please read the Qt Code of Conduct -

Linking SFML Libraries to Qt Project [linking errors]

  • Hi there,

    I'm attempting to create a simple project using Qt Creator. I'm in the process of learning both Qt and the SFML library.

    I have attempted to link to the SFML library, but am running into issues. Whenever I attempt to a class defined in the sfml-audio-s.lib library, I get the linker errors:


    These errors state that there are unresolved external symbols. Now while it states it can't find 'soundmachine.obj' which is a class that I have defined internally to my Qt project, these errors only pop up once I try to use the classes in the SFML library. This leads me to believe that something is not be linked correctly.

    Also note that I'm getting a warning stating that my libraries are targeted for x86 but my project is targeted for x64. I'm okay with this, assuming it's not what is causing this issue.

    Furthermore, I'm linking to these libraries in the following fashion:

    1. I right click the project to add a library.

    2. I select the 'add external library' option.


    1. I then navigate to the SFML audio lib file, and the include directory. Note that I choose the sfml-audio-s.lib file. This is the .lib that should be used for static libraries as it contains all of the classes and functions.


    1. It then generates the appropriate text to place into the qmake file.


    By now, I assume I should be good to go. I should be able to use all of the classes in the SFML library from my Qt project. However, as soon as I attempt to make an instance of SFML's class object, I get those linker errors.

    I'm running out of ideas on how to troubleshoot this...

    Any ideas?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You are trying to link a 32bit library against your 64bit application.

    One other thing to take into consideration with Windows: ensure you are using the same compiler for all dependencies. You can't mix and match compilers i.e. different version of Visual Studio are not compatible one with the other.

  • Hi SGaist,

    Thank you for the response. I assumed this wouldn't be an issue seeing as how 32bit and 64 bit applications can run on a x64 architecture.

    Two questions:

    1. How exactly do you configure the project to target x64? I attempted to create a kit, but it won't allow me to select that kit after creating it. When I select the Qt version, I select the Qt version I have which is 5.7 64 bit, but it states that this version of Qt can not target x86 architecture. Does this make sense? Would I really need to install an x86 version to create x86 applications?

    2. I think I need a formal rundown on understanding how libraries work in Windows. I always assumed that you have static libraries (.lib) and dynamic libraries (.dll). However, when configuring the project in Qt Creator (as well as my experiences with Visual Studio), you are required to specify a .lib when adding a library regardless of whether or not it will be used as a static or dynamic library. So my question: do you need prior information of a .lib file to know whether or not it refer to a dynamic or static library? That is, are .lib used for both dynamic and static libraries? And for a static library, the .lib file contains actual compiled code, while for a dynamic library, the .lib contains some part that says "I'm a dynamic library, go look else where for the dlls"?


  • Lifetime Qt Champion

    Indeed a 32bit application can run on a 64bit Windows. However that doesn't mean to you can mix architecture when linking your application.

    1. Yes it make sense. You have to install the 32 bit version of your libraries. Or build SFML for 64 bit.
    2. On Windows the .lib files can either be a static library or an import file when using shared library but they are different files. Usually a static library is pretty large compared to a simple import file.

  • @SGaist

    So I've installed the 32 bit version of Qt such that I could have my project target an x86 machine. However, it didn't seem to fix the problem.

    I'm getting the following error:

    This appears to still be a linking error. However, what confuses is my is that the errors feature dllimport messages. However, I've configured my libraries to be linked statically... These shouldn't even be popping up..

  • Lifetime Qt Champion

    Did you compile SFML statically ? With the same compiler you use for your application ?

  • @SGaist

    Hmm... I assumed the compiler version that the library was generated on wouldn't be a big deal... But now that I look at it, it seems like there are several download options for the library. Link to SFML libs

    I can look further into this, but I just assumed it wouldn't be a big deal.

    This is thus stemming from my inexperience with Windows libraries I suppose. Another general question, why does the compiler option even matter? If the library was compiled with MVCC 11/12/14 targeting x86, shouldn't they all contain compatible x86 obj files?

    I've never written my own static or dynamic library in Windows, but are there custom C++ extensions that are dependent on the compiler version that Microsoft inroduces? Thus there may be some new/different C++ extensions in the a .lib created with MVCC14, thus it won't be understood when trying to link to a project using MVCC11?

  • Lifetime Qt Champion

    Like I already wrote before: the compilers from different versions of Visual Studio are not compatible one with the other.

    See here for the reasons.

Log in to reply