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

Author Topic: Project links to dynamic library just fine, but it won't link to static library  (Read 1296 times)

0 Members and 1 Guest are viewing this topic.

tomizzo11

  • Newbie
  • *
  • Posts: 3
    • View Profile
I had previously posted a question trying to inquire about the difference between the MSVC x86 SFML lib downloads. I had been having library problems and I assumed I had downloaded the wrong library version and downloading the correct library would fix it. However, I'm still having issues so I've decided to post this thread as a more direct request for help. Now onto the issue.

I'm currently working on a Qt project where I plan on using SFML. I'm running into a problem when I attempt to statically link to the library.My Qt project is configured to use the MSVC2015 32bit compiler and I have downloaded the MSVC2015 32 bit SFML library.

A screen shot of the Qt project configuration is located here: http://imgur.com/a/uQpTd

The corresponding qmake code is added to the .pro file: http://imgur.com/a/DkIjp

So I believe I should be all set to start using the static library. I will attempt to create an SoundBuffer instance (a class defined within the static library).

Quote
#include "mainwindow.h"
#include <QApplication>
#include <SFML/Audio.hpp>

int main(int argc, char *argv[])
{
    sf::SoundBuffer buffer;
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

I then proceed to get the following errors: http://imgur.com/a/tz9lK

The build process fails when I attempt this. However, if I comment out the SoundBuffer, the project builds fine.

It states that there are unresolved external symbols. Now I am a noobie with linking to static libraries, but I assume this means that it can't find the corresponding class in the .lib file. It knows that it exists due to the header file, but it can't actually determine how it is defined. Am I correct in assuming this?

The next red flag that is raised is the the fact that it is generating .dll related messages even though I'm using a static library. I have also verified countless times that the library I'm trying to link to is in face a static library.

HOWEVER, if I decide the link against the dynamic library (via the import library), the project builds just fine. I then move the dll's to the directory containing the .exe files and the project runs just fine with no crash.

So what exactly is going on? Why can't I link against the static library, but I can link against the dynamic version just fine? Furthermore, why does the compiler generate linker issues stating that there are unresolved external symbols and then proceeds to mention the declspec(dllimport)? I'm not using the library as a dynamic library...

Any recommendations of the next step of troubleshooting?

Fumasu

  • Newbie
  • *
  • Posts: 3
    • View Profile
Hi,

as stated in http://www.sfml-dev.org/tutorials/2.4/start-vc.php

Quote
If you want to get rid of these DLLs and have SFML directly integrated into your executable, you must link to the static version. Static SFML libraries have the "-s" suffix: "sfml-xxx-s-d.lib" for Debug, and "sfml-xxx-s.lib" for Release.
 In this case, you'll also need to define the SFML_STATIC macro in the preprocessor options of your project.
and
Quote
Starting from SFML 2.2, when static linking, you will have to link all of SFML's dependencies to your project as well. This means that if you are linking sfml-window-s.lib or sfml-window-s-d.lib for example, you will also have to link opengl32.lib, winmm.lib and gdi32.lib. Some of these dependency libraries might already be listed under "Inherited values", but adding them again yourself shouldn't cause any problems.

Have you tried that??

tomizzo11

  • Newbie
  • *
  • Posts: 3
    • View Profile
Ahhh, interesting. I had defined the SFML_STATIC macro but did not do the second part. Let me give that a try and I will edit this with an update.

EDIT: This indeed was the problem! I do recall this dependency issue a while back but must have forgotten about it. Thank you very much!
« Last Edit: August 25, 2016, 05:45:19 am by tomizzo11 »