0

I'm creating a library that use GLFW and Glad. I'm exposing high level functions to create a window and 2D rendering. But I don't want that users using the library have access to GLFW and Glad functions. I want that only the library can access to theses functions. I'm wondering if it's possible because all the implementation are in the .a file ? I compile everything to static libs.

Sorry for the title. Let me know if you find a better one.

droyer
  • 13
  • 4
  • 1
    Aren't you deploying also a header file alongside the binary? In the header you decide what's available. – MatG Apr 11 '21 at 16:25
  • ***I'm wondering if it's possible*** Yes. Its possible and completely unrelated to an .a file. You can isolate the implementation and not give any access to the headers of the libraries you are using in the public interface of your library. One thing that may help you is using PIMPL: [https://stackoverflow.com/questions/60570/why-should-the-pimpl-idiom-be-used](https://stackoverflow.com/questions/60570/why-should-the-pimpl-idiom-be-used) – drescherjm Apr 11 '21 at 16:46
  • 1
    As @MatG said using header files should solve your problem. Just make sure that the exposed header file does not include any header from the above libraries as it clearly beats the point! – Raviteja Narra Apr 11 '21 at 16:48
  • I have a header file named `Application.h`. I'm using a `GLFWwindow*` so I have no choice to include `GLFW/glfw3.h`. In an other app using my lib, I need to include `Application.h` to create a window. But all the implementation of GLFW are stored in the `.a` file because I used the static linking. So I can access to any GLFW functions on my app and I don't want that. Only my lib is supposed to use GLFW. – droyer Apr 11 '21 at 17:05
  • ***so I have no choice to include*** Don't include `GLFW/glfw3.h` in the header you make public if your goal is to remove access to this library. You can always hide the implementation detail from the public interface. – drescherjm Apr 11 '21 at 18:09
  • An other option is perhaps `class GLFWwindow;` would be sufficient in the public header instead of the include. – drescherjm Apr 11 '21 at 18:13
  • @drescherjm It's working with `class GLFWwindow;` but I still can include `GLFW/glfw3.h` on my main app. It will work because all the implementation on GLFW are in the lib file. – droyer Apr 11 '21 at 18:41
  • I compile like so : `g++ App.cpp -ITestEngine/include libTestEngine.a libglfw3.a -ldl /usr/lib/libX11.so -pthread`. I link with GLFW because my lib use it. But in my main app, I can also use GLFW. I want to avoid that if it's possible. – droyer Apr 11 '21 at 20:19
  • In any way, you cannot prevent an executable from using GLFW at binary level. So just do not bother about that. – Tsyvarev Apr 11 '21 at 21:12

0 Answers0