# Linking GLFW as shared object

**URL:** <https://discourse.glfw.org/t/linking-glfw-as-shared-object/1066>\
**Category:** support\
**Created:** [January 17, 2018, 1:35pm UTC](https://discourse.glfw.org/t/linking-glfw-as-shared-object/1066 "2018-01-17T13:35:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Overblade](https://avatars.discourse-cdn.com/v4/letter/o/b2d939/32.png) [@Overblade](https://discourse.glfw.org/u/Overblade)\
**Post date:** [January 17, 2018, 1:35pm UTC](https://discourse.glfw.org/t/linking-glfw-as-shared-object/1066/1 "2018-01-17T13:35:48Z")

</div>

I really enjoy GLFW’s interface which is why I use it in every project where I have to deal with windows.

Now I wanted to try something new: In my earlier projects I compiled GLFW along with my source code. To not have to deal with many files, I compiled GLFW as shared library (.so) and put it in a folder called `/lib`. My executable ends up in the folder `/bin`, where a soft link referres to `/lib`. As a result, the directory tree looks like this:

```
root
|- /bin
| |- /lib (link)
| | |- libglfw.so (link)
| |
| |- executable
|
|- /lib
| |- libglfw.so
|
|- /include (...) //GLFW includes
|
|- /src
  |- (...)

```

Before compiling GLFW I set `BUILD_SHARED_LIBS` to `ON`. Usage is as follows:

```
#include <iostream>
#define GLFW_DLL
#include <GLFW/glfw3.h>

int main(){

    std::cout << "test1" << std::endl;

    int a = glfwInit();
    std::cout << "test2" << std::endl;

}

```

In eclipse I set gcc’s -l flag to glfw and -L flag to `lib/`. I even set the `LD_LIBRARY_PATH` variable to `/lib` and it compiles without any issues.  
However, all I get is a nice line of linker output (at runtime):

```
/bin/Editor: error while loading shared libraries: libglfw.so.3: cannot open shared object file: No such file or directory

```

I couldn’t find any solution online, so that’s why I ask here. Did I made a mistake when compiling the library?  
I am really desperate because of this nasty linker error.  
Thank you very much in advance.

---

<div class="post-metadata">

**Author:** ![Overblade](https://avatars.discourse-cdn.com/v4/letter/o/b2d939/32.png) [@Overblade](https://discourse.glfw.org/u/Overblade)\
**Post date:** [January 17, 2018, 3:51pm UTC](https://discourse.glfw.org/t/linking-glfw-as-shared-object/1066/2 "2018-01-17T15:51:17Z")

</div>

Ok I solved it. I was not allowed to modify the .so file’s version suffix. When I compile with libglfw.so.3 it correctly links and executes.
