www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Linking a shared library in dub

reply maik klein <maikklein googlemail.com> writes:
I want to finally convert my project to windows. That means that 
I want to build it on windows and linux.

The problem is that I have one external c library 'glfw'. I 
thought that I would just link with it explicitly but actually I 
am not completely sure how.


So I just added a submodule, cloned glfw and build it as a shared 
library

lflags "deps/glfw/build/src/libglfw.so"


This is the eps/glfw/build/src folder:

total 196K
drwxr-xr-x 3 maik users 4.0K Mar 30 14:07 .
drwxr-xr-x 6 maik users 4.0K Mar 30 14:07 ..
drwxr-xr-x 3 maik users 4.0K Mar 30 14:07 CMakeFiles
-rw-r--r-- 1 maik users 2.1K Mar 30 14:07 cmake_install.cmake
-rw-r--r-- 1 maik users   56 Mar 30 14:07 glfw3Config.cmake
-rw-r--r-- 1 maik users 1.6K Mar 30 14:07 glfw3ConfigVersion.cmake
-rw-r--r-- 1 maik users  348 Mar 30 14:07 glfw3.pc
-rw-r--r-- 1 maik users 3.1K Mar 30 14:07 glfw_config.h
lrwxrwxrwx 1 maik users   12 Mar 30 14:07 libglfw.so -> 
libglfw.so.3
lrwxrwxrwx 1 maik users   14 Mar 30 14:07 libglfw.so.3 -> 
libglfw.so.3.2
-rwxr-xr-x 1 maik users 142K Mar 30 14:07 libglfw.so.3.2
-rw-r--r-- 1 maik users  18K Mar 30 14:07 Makefile


But If I try to build it with dub, i'll get "./bin/breeze_opengl: 
error while loading shared libraries: libglfw.so.3: cannot open 
shared object file: No such file or directory"

But as you can see it is in there. I get the same error with

lflags "deps/glfw/build/src/libglfw.so.3"
lflags "deps/glfw/build/src/libglfw.so.3.2"

Also the path seems to be correct because if I try to add a file 
that not exisit I get a different error
lflags "deps/glfw/build/src/doesnotexist.so"

/usr/bin/ld: cannot find deps/glfw/build/src/doesnotexist.so: No 
such file or directory
collect2: error: ld returned 1 exit status

Am I doing something wrong?
Mar 30 2016
parent reply Vadim Lopatin <coolreader.org gmail.com> writes:
On Wednesday, 30 March 2016 at 12:19:34 UTC, maik klein wrote:
 I want to finally convert my project to windows. That means 
 that I want to build it on windows and linux.

 The problem is that I have one external c library 'glfw'. I 
 thought that I would just link with it explicitly but actually 
 I am not completely sure how.
Try using Derelict based binding http://code.dlang.org/packages/derelict-glfw3
Mar 30 2016
parent reply maik klein <maikklein googlemail.com> writes:
On Wednesday, 30 March 2016 at 12:46:08 UTC, Vadim Lopatin wrote:
 On Wednesday, 30 March 2016 at 12:19:34 UTC, maik klein wrote:
 I want to finally convert my project to windows. That means 
 that I want to build it on windows and linux.

 The problem is that I have one external c library 'glfw'. I 
 thought that I would just link with it explicitly but actually 
 I am not completely sure how.
Try using Derelict based binding http://code.dlang.org/packages/derelict-glfw3
I am already using the derelict binding but I want to explicitly link with the .a or .so c lib because I don't have a package manager on windows.
Mar 30 2016
parent reply maik klein <maikklein googlemail.com> writes:
On Wednesday, 30 March 2016 at 17:38:15 UTC, maik klein wrote:
 On Wednesday, 30 March 2016 at 12:46:08 UTC, Vadim Lopatin 
 wrote:
 On Wednesday, 30 March 2016 at 12:19:34 UTC, maik klein wrote:
 I want to finally convert my project to windows. That means 
 that I want to build it on windows and linux.

 The problem is that I have one external c library 'glfw'. I 
 thought that I would just link with it explicitly but 
 actually I am not completely sure how.
Try using Derelict based binding http://code.dlang.org/packages/derelict-glfw3
I am already using the derelict binding but I want to explicitly link with the .a or .so c lib because I don't have a package manager on windows.
Okay I think I understand know what you mean, I think you meant I should use dynamic loading like this right? DerelictGLFW3.load("deps/glfw/build/src/libglfw.so"); This works but I am not sure yet that I want to load it at the application level.
Mar 30 2016
parent maik klein <maikklein googlemail.com> writes:
On Thursday, 31 March 2016 at 00:06:19 UTC, maik klein wrote:
 On Wednesday, 30 March 2016 at 17:38:15 UTC, maik klein wrote:
 On Wednesday, 30 March 2016 at 12:46:08 UTC, Vadim Lopatin 
 wrote:
 On Wednesday, 30 March 2016 at 12:19:34 UTC, maik klein wrote:
 I want to finally convert my project to windows. That means 
 that I want to build it on windows and linux.

 The problem is that I have one external c library 'glfw'. I 
 thought that I would just link with it explicitly but 
 actually I am not completely sure how.
Try using Derelict based binding http://code.dlang.org/packages/derelict-glfw3
I am already using the derelict binding but I want to explicitly link with the .a or .so c lib because I don't have a package manager on windows.
Okay I think I understand know what you mean, I think you meant I should use dynamic loading like this right? DerelictGLFW3.load("deps/glfw/build/src/libglfw.so"); This works but I am not sure yet that I want to load it at the application level.
I was able to link with a static lib like this dependency "derelict-glfw3" version="~>2.0.0" subConfiguration "derelict-glfw3" "derelict-glfw3-static" sourceFiles "deps/glfw/build/src/libglfw3.a" libs "Xi" "pthread" "X11" "Xxf86vm" "Xrandr" "pthread" "GL" "GLU" "Xinerama" "Xcursor"
Mar 30 2016