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

Author Topic: Using SFML in own dll  (Read 6864 times)

0 Members and 2 Guests are viewing this topic.

kralo9

  • Newbie
  • *
  • Posts: 44
    • View Profile
    • Email
Using SFML in own dll
« on: June 12, 2013, 10:40:51 am »
I would like to know if and how i can include the sfml library in my own dll so wehn i am using my dll i need not to include the sfml library but only my own.
I'm totally exhausted. I've got 3 children and no money! Why can't I have no children and 3 money? - Homer S.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Using SFML in own dll
« Reply #1 on: June 12, 2013, 10:45:10 am »
The exact same way you would include and link it to an executable. Use static linking if you also want to get rid of the SFML DLLs at runtime.

Everything is explained in the tutorials.
Laurent Gomila - SFML developer

kralo9

  • Newbie
  • *
  • Posts: 44
    • View Profile
    • Email
Re: Using SFML in own dll
« Reply #2 on: June 12, 2013, 03:35:32 pm »
My problem is that if i include my dll in my executable the compiler starts complaining about functions of sfml it cannot find :/
I'm totally exhausted. I've got 3 children and no money! Why can't I have no children and 3 money? - Homer S.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Using SFML in own dll
« Reply #3 on: June 12, 2013, 03:38:19 pm »
If the executable uses SFML functions directly then it must also link to SFML.

Note that I'm just guessing here, because your messages are not very detailed. Please say exactly what you do (what you include/link and how), what error messages you get, etc.

http://en.sfml-dev.org/forums/index.php?topic=5559.0
Laurent Gomila - SFML developer

kralo9

  • Newbie
  • *
  • Posts: 44
    • View Profile
    • Email
Re: Using SFML in own dll
« Reply #4 on: June 13, 2013, 07:28:48 pm »
Actually you replied what I wanted to know. It was just that short because I've written those messages with my mobile. Thanks for help :)
I'm totally exhausted. I've got 3 children and no money! Why can't I have no children and 3 money? - Homer S.

kralo9

  • Newbie
  • *
  • Posts: 44
    • View Profile
    • Email
Re: Using SFML in own dll
« Reply #5 on: June 14, 2013, 08:13:27 pm »
Well I've some problems with including the header:
Example:

(Of course there are include guards, namespace etc. but I left them to keep it short)

window.h

#include <SFML/Graphics.hpp>

class Window : public sf::RenderWindow{
public:
   const float& update();
...
};

 

and in my executable
#include <GSE/Window.h>

...
Window window;
...

 

And I'm getting errors, that it cannot find SFML/Graphics.hpp. He found the error in the Window.h. Looks like my compiler is trying to recompile my library.

How do I do it right?

VC++ is my IDE
I'm totally exhausted. I've got 3 children and no money! Why can't I have no children and 3 money? - Homer S.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Using SFML in own dll
« Reply #6 on: June 14, 2013, 08:27:13 pm »
Make sure the SFML headers are in the path of include directories. Everything is explained in the official tutorial, please read it carefully.

And returning a const-reference to float is pointless. Just return a copy.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

kralo9

  • Newbie
  • *
  • Posts: 44
    • View Profile
    • Email
Re: Using SFML in own dll
« Reply #7 on: June 14, 2013, 08:31:48 pm »
Make sure the SFML headers are in the path of include directories. Everything is explained in the official tutorial, please read it carefully.

So I do have to include SFML to my executable... I wanted to include my lib only...

And returning a const-reference to float is pointless. Just return a copy.

Why is it pointless?
I'm totally exhausted. I've got 3 children and no money! Why can't I have no children and 3 money? - Homer S.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Using SFML in own dll
« Reply #8 on: June 14, 2013, 08:41:43 pm »
I think he wants to create dll that when included provides SFML without need to include/link it explicitly.

Quote
Why is it pointless?
floats are usually 4 bytes, pointers(so references too) are 4 or 8(so more or equal) + there is cost of dereferencing and so on..
Back to C++ gamedev with SFML in May 2023

kralo9

  • Newbie
  • *
  • Posts: 44
    • View Profile
    • Email
Re: Using SFML in own dll
« Reply #9 on: June 14, 2013, 08:42:58 pm »
I think he wants to create dll that when included provides SFML without need to include/link it explicitly.

Quote
Why is it pointless?
floats are usually 4 bytes, pointers(so references too) are 4 or 8(so more or equal) + there is cost of dereferencing and so on..

1. Yes, that's what I want to have! :) Tell me how to do this.
2. Ok understood, thanks
« Last Edit: June 14, 2013, 09:03:09 pm by kralo9 »
I'm totally exhausted. I've got 3 children and no money! Why can't I have no children and 3 money? - Homer S.

kralo9

  • Newbie
  • *
  • Posts: 44
    • View Profile
    • Email
Re: Using SFML in own dll
« Reply #10 on: June 14, 2013, 09:35:35 pm »
Maybe short instruction to do that in VC++, please?

Oups, should have been an edit...
I'm totally exhausted. I've got 3 children and no money! Why can't I have no children and 3 money? - Homer S.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Using SFML in own dll
« Reply #11 on: June 14, 2013, 11:00:59 pm »
I don't know if that's possible without doing something like embedding entire code of SFML into your dll, someone more guru in windows like Nexus or Laurent will have to give definitive answer to that.
I link my dll to all I need statically or dynamically(SFML,Thor and SFG dynamically), link from exe to SFML/SFG/Thor/whatever too and I have all include files in common folder D:/Libs/include/
dlls load once per process so SFG, Thor, my dll and exe use the same SFML dll, and my dll and exe use the same SFG and Thor dll.
« Last Edit: June 14, 2013, 11:03:11 pm by FRex »
Back to C++ gamedev with SFML in May 2023

kralo9

  • Newbie
  • *
  • Posts: 44
    • View Profile
    • Email
Re: Using SFML in own dll
« Reply #12 on: June 14, 2013, 11:08:35 pm »
Is there no other way to achieve that without implementing all sfml code into my dll?
I'm totally exhausted. I've got 3 children and no money! Why can't I have no children and 3 money? - Homer S.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Using SFML in own dll
« Reply #13 on: June 15, 2013, 12:20:57 am »
Quote
someone more guru in windows like Nexus or Laurent will have to give definitive answer to that.
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Using SFML in own dll
« Reply #14 on: June 15, 2013, 08:39:17 am »
If SFML was a hidden implementation detail of your library, your executable wouldn't have to include or link anything about SFML (unless your library is a static one).

But, since SFML appears in the public interface of your library, the executable indirectly uses it. In particular, it indirectly includes some SFML headers. So it has to know where they are, so you have to configure your project accordingly.

But this is a design issue, not a technical one. Either you want SFML to be a hidden detail, and you do whatever is required to actually hide all SFML classes and calls, or it's really part of your public API and you accept that your library is not independant, it's a SFML add-on, which requires SFML to be used.
Laurent Gomila - SFML developer