4 Replies - 402 Views - Last Post: 02 August 2014 - 09:59 AM Rate Topic: -----

#1 Fatov  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 08-May 14

How to write a own library and hide other used libraries

Posted 01 August 2014 - 01:14 PM

Hello,
I want to write a small game library that uses GLFW.
So I have for example a window class that uses GLFW functions.
To do that my window class must include the GLFW header files.
But I don't want, that if I use my library later and I include my window class, that all GLFW functions are included, too.
How I can prevent this and hide GLFW from users of this library completely, so they theoretical don't notice that this library use GLFW ?
And a second question, is it possible, if I export my game library statically that the GLFW lib files are hidden in my own lib files, so that I have finally only one lib file that is needed to use my library ?

Is This A Good Question/Topic? 0
  • +

Replies To: How to write a own library and hide other used libraries

#2 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 810
  • View blog
  • Posts: 2,407
  • Joined: 20-March 10

Re: How to write a own library and hide other used libraries

Posted 01 August 2014 - 04:10 PM

What you want to write is a wrapper class for GLFW,

so the short answer is no you cant really hide the fact you have used GLFW as the header(s) for your library will

reference GLFW headers.

If you have built GLFW as a static lib then yes the GLFW lib will be inside your lib.

As an aside game libraries tend to have sound capabilities and joystick/keyboard/mouse input handling and some network capabilities not just graphics capabilities some thing to think about as GLFW cannot provide any of those.

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#3 Fatov  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 08-May 14

Re: How to write a own library and hide other used libraries

Posted 02 August 2014 - 03:58 AM

But is it relay not possible to hide the glfw headers for people who use my library,
so for example if I have a window class and someone include it I don't want that the, from the window class needed, glfw header files are automatically included, too?
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3623
  • View blog
  • Posts: 11,291
  • Joined: 05-May 12

Re: How to write a own library and hide other used libraries

Posted 02 August 2014 - 06:32 AM

It is possible to hide the headers. Look into the PIMPL pattern. Your public headers will only have what you want exposed to the user. Those classes in the header will have pointers to classes where you have you actual implementation where your implementation includes the GLFW headers. Since the end user doesn't need to include the GLFW headers when they compile, you've effectively hidden them.

Linking maybe harder, though if you can't statically put GLFW binaries completely into your library.
Was This Post Helpful? 0
  • +
  • -

#5 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 810
  • View blog
  • Posts: 2,407
  • Joined: 20-March 10

Re: How to write a own library and hide other used libraries

Posted 02 August 2014 - 09:59 AM

Interesting never though of that..

so your saying.... put your declaration and implementation into a .cpp file and then have a .h file that implements pointers to those classes ? so your includes will be hidden in the .cpp file as well ??

Might take some jigging about but I could see how it could work....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1