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

Author Topic: Linking SFML static lib into a DLL?  (Read 1358 times)

0 Members and 1 Guest are viewing this topic.

TheComet

  • Newbie
  • *
  • Posts: 12
    • View Profile
Linking SFML static lib into a DLL?
« on: June 27, 2013, 01:49:38 pm »
Hi,

I have the following problem. I would like to use the static libs of SFML, not the dynamic ones.

However, my project is a DLL (the DLL is intended to be used in another language), so the static SFML libs need to be linked against the dll.

I'm using Visual C++ Express 2008, and get the following errors:
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Clock::clock(void)" (__imp_??0Clock@sf@@QAE@XZ) referenced in function "public: __thiscall cSomeClass::cSomeClass(void)"

The class in the static library looks like this:

class cSomeClass
{
public:
   cSomeClass(void){ m_Clock = new sf::Clock(); }
   ~cSomeClass(void){ delete m_Clock; }
private:
   sf::Clock* m_Clock;
};

Is there something I'm missing? From what I've found on google, linking static libs into DLLs is a royal pain.

I also came across the linker option used in GCC --whole-archive, which would force the inclusion of the entire static library and resolve the problem above. What is the equivalent in VC++?

Do I need to do something with SFML_SYSTEM_EXPORTS to make everything visible to the DLL?

Thanks,

TheComet

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Linking SFML static lib into a DLL?
« Reply #1 on: June 27, 2013, 02:01:17 pm »
Quote
From what I've found on google, linking static libs into DLLs is a royal pain
Not at all, it's the same as linking to an executable.

You forgot to define the SFML_STATIC macro (this is explained in the tutorial...).
Laurent Gomila - SFML developer

TheComet

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Linking SFML static lib into a DLL?
« Reply #2 on: June 27, 2013, 02:25:13 pm »
Thanks for the quick reply. That worked perfectly.  ;)

 

anything