diff mbox

[2/4] libselinux,libsemanage: link Ruby wrapper with -lruby

Message ID 20161114212817.15781-2-nicolas.iooss@m4x.org (mailing list archive)
State Not Applicable
Headers show

Commit Message

Nicolas Iooss Nov. 14, 2016, 9:28 p.m. UTC
When linking with -Wl,-no-undefined in LDFLAGS (in order to find
possible link-time errors), the Ruby wrapper module needs to be linked
with the libruby.so which is used by $(RUBY). Introduce a new RUBYLIBS
variable to find this library.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
 libselinux/src/Makefile  | 3 ++-
 libsemanage/src/Makefile | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

Comments

Laurent Bigonville June 21, 2017, 9:38 a.m. UTC | #1
Hello,

Le 14/11/16 à 22:28, Nicolas Iooss a écrit :
> When linking with -Wl,-no-undefined in LDFLAGS (in order to find
> possible link-time errors), the Ruby wrapper module needs to be linked
> with the libruby.so which is used by $(RUBY). Introduce a new RUBYLIBS
> variable to find this library.
>
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
> ---
>   libselinux/src/Makefile  | 3 ++-
>   libsemanage/src/Makefile | 3 ++-
>   2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
> index 4fe1f7002181..82a1010af2d8 100644
> --- a/libselinux/src/Makefile
> +++ b/libselinux/src/Makefile
> @@ -15,6 +15,7 @@ INCLUDEDIR ?= $(PREFIX)/include
>   PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
>   PYSITEDIR ?= $(DESTDIR)$(shell $(PYTHON) -c 'import site; print(site.getsitepackages()[0])')
>   RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + RbConfig::CONFIG["rubyarchhdrdir"] + " -I" + RbConfig::CONFIG["rubyhdrdir"]')
> +RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -lruby"')

I'm trying to package 2.7-rc2 in debian and unfortunately this is not 
working out of the box for me. The library is not installed as -lruby 
but as -lruby-2.3 (for ruby 2.3). In addition the lib is not installed 
in /usr/lib.

I can see in the RbConfig::CONFIG hash a key called LIBRUBYARG_SHARED or 
LIBRUBYARG which contains "-lruby-2.3". Also I see a "archlibdir" or 
"sitearchlibdir" key which contains the correct path to the lib (the 
multiarch path)

RUBYLIBS ?= $(shell $@ -e 'puts "-L" + RbConfig::CONFIG["archlibdir"] + 
" " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')

Could this be a possible alternatives for the other distributions?

Regards,

Laurent Bigonville
Stephen Smalley June 21, 2017, 1:42 p.m. UTC | #2
On Wed, 2017-06-21 at 11:38 +0200, Laurent Bigonville wrote:
> Hello,
> 
> Le 14/11/16 à 22:28, Nicolas Iooss a écrit :
> > When linking with -Wl,-no-undefined in LDFLAGS (in order to find
> > possible link-time errors), the Ruby wrapper module needs to be
> > linked
> > with the libruby.so which is used by $(RUBY). Introduce a new
> > RUBYLIBS
> > variable to find this library.
> > 
> > Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
> > ---
> >   libselinux/src/Makefile  | 3 ++-
> >   libsemanage/src/Makefile | 3 ++-
> >   2 files changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
> > index 4fe1f7002181..82a1010af2d8 100644
> > --- a/libselinux/src/Makefile
> > +++ b/libselinux/src/Makefile
> > @@ -15,6 +15,7 @@ INCLUDEDIR ?= $(PREFIX)/include
> >   PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
> >   PYSITEDIR ?= $(DESTDIR)$(shell $(PYTHON) -c 'import site;
> > print(site.getsitepackages()[0])')
> >   RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" +
> > RbConfig::CONFIG["rubyarchhdrdir"] + " -I" +
> > RbConfig::CONFIG["rubyhdrdir"]')
> > +RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" +
> > RbConfig::CONFIG["libdir"] + " -lruby"')
> 
> I'm trying to package 2.7-rc2 in debian and unfortunately this is
> not 
> working out of the box for me. The library is not installed as
> -lruby 
> but as -lruby-2.3 (for ruby 2.3). In addition the lib is not
> installed 
> in /usr/lib.
> 
> I can see in the RbConfig::CONFIG hash a key called LIBRUBYARG_SHARED
> or 
> LIBRUBYARG which contains "-lruby-2.3". Also I see a "archlibdir" or 
> "sitearchlibdir" key which contains the correct path to the lib (the 
> multiarch path)
> 
> RUBYLIBS ?= $(shell $@ -e 'puts "-L" + RbConfig::CONFIG["archlibdir"]
> + 
> " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
> 
> Could this be a possible alternatives for the other distributions?

Assuming you mean $(RUBY) rather than $@ above, that works for me on
Fedora:
$ ruby -e 'puts "-L" + RbConfig::CONFIG["archlibdir"] + " " +
RbConfig::CONFIG["LIBRUBYARG_SHARED"]'
-L/usr/lib64 -lruby
Nicolas Iooss June 21, 2017, 2:02 p.m. UTC | #3
On Wed, Jun 21, 2017 at 3:42 PM, Stephen Smalley <sds@tycho.nsa.gov> wrote:
> On Wed, 2017-06-21 at 11:38 +0200, Laurent Bigonville wrote:
>> Hello,
>>
>> Le 14/11/16 à 22:28, Nicolas Iooss a écrit :
>> > When linking with -Wl,-no-undefined in LDFLAGS (in order to find
>> > possible link-time errors), the Ruby wrapper module needs to be
>> > linked
>> > with the libruby.so which is used by $(RUBY). Introduce a new
>> > RUBYLIBS
>> > variable to find this library.
>> >
>> > Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
>> > ---
>> >   libselinux/src/Makefile  | 3 ++-
>> >   libsemanage/src/Makefile | 3 ++-
>> >   2 files changed, 4 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
>> > index 4fe1f7002181..82a1010af2d8 100644
>> > --- a/libselinux/src/Makefile
>> > +++ b/libselinux/src/Makefile
>> > @@ -15,6 +15,7 @@ INCLUDEDIR ?= $(PREFIX)/include
>> >   PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
>> >   PYSITEDIR ?= $(DESTDIR)$(shell $(PYTHON) -c 'import site;
>> > print(site.getsitepackages()[0])')
>> >   RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" +
>> > RbConfig::CONFIG["rubyarchhdrdir"] + " -I" +
>> > RbConfig::CONFIG["rubyhdrdir"]')
>> > +RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" +
>> > RbConfig::CONFIG["libdir"] + " -lruby"')
>>
>> I'm trying to package 2.7-rc2 in debian and unfortunately this is
>> not
>> working out of the box for me. The library is not installed as
>> -lruby
>> but as -lruby-2.3 (for ruby 2.3). In addition the lib is not
>> installed
>> in /usr/lib.
>>
>> I can see in the RbConfig::CONFIG hash a key called LIBRUBYARG_SHARED
>> or
>> LIBRUBYARG which contains "-lruby-2.3". Also I see a "archlibdir" or
>> "sitearchlibdir" key which contains the correct path to the lib (the
>> multiarch path)
>>
>> RUBYLIBS ?= $(shell $@ -e 'puts "-L" + RbConfig::CONFIG["archlibdir"]
>> +
>> " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
>>
>> Could this be a possible alternatives for the other distributions?
>
> Assuming you mean $(RUBY) rather than $@ above, that works for me on
> Fedora:
> $ ruby -e 'puts "-L" + RbConfig::CONFIG["archlibdir"] + " " +
> RbConfig::CONFIG["LIBRUBYARG_SHARED"]'
> -L/usr/lib64 -lruby

On Arch Linux:

$ ruby -e 'puts RbConfig::CONFIG["LIBRUBYARG"]'
-lruby
$ ruby -e 'puts RbConfig::CONFIG["LIBRUBYARG_SHARED"]'
-lruby
$ ruby -e 'puts RbConfig::CONFIG["archlibdir"]'
/usr/lib/x86_64-linux
$ ls -l /usr/lib/x86_64-linux/libruby.so
ls: cannot access '/usr/lib/x86_64-linux/libruby.so': No such file or directory
$ ruby -e 'puts RbConfig::CONFIG["libdir"]'
/usr/lib
$ ls -l /usr/lib/libruby.so
lrwxrwxrwx 1 root root 16 2017-04-22 15:40 /usr/lib/libruby.so ->
libruby.so.2.4.1*

So replacing -lruby with RbConfig::CONFIG["LIBRUBYARG_SHARED"] and
adding "-L" + RbConfig::CONFIG["archlibdir"] in RUBYLIBS definition
seem to work fine.

Nicolas
Jason Zaman June 21, 2017, 2:27 p.m. UTC | #4
On Wed, Jun 21, 2017 at 04:02:29PM +0200, Nicolas Iooss wrote:
> On Wed, Jun 21, 2017 at 3:42 PM, Stephen Smalley <sds@tycho.nsa.gov> wrote:
> > On Wed, 2017-06-21 at 11:38 +0200, Laurent Bigonville wrote:
> >> Hello,
> >>
> >> Le 14/11/16 à 22:28, Nicolas Iooss a écrit :
> >> > When linking with -Wl,-no-undefined in LDFLAGS (in order to find
> >> > possible link-time errors), the Ruby wrapper module needs to be
> >> > linked
> >> > with the libruby.so which is used by $(RUBY). Introduce a new
> >> > RUBYLIBS
> >> > variable to find this library.
> >> >
> >> > Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
> >> > ---
> >> >   libselinux/src/Makefile  | 3 ++-
> >> >   libsemanage/src/Makefile | 3 ++-
> >> >   2 files changed, 4 insertions(+), 2 deletions(-)
> >> >
> >> > diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
> >> > index 4fe1f7002181..82a1010af2d8 100644
> >> > --- a/libselinux/src/Makefile
> >> > +++ b/libselinux/src/Makefile
> >> > @@ -15,6 +15,7 @@ INCLUDEDIR ?= $(PREFIX)/include
> >> >   PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
> >> >   PYSITEDIR ?= $(DESTDIR)$(shell $(PYTHON) -c 'import site;
> >> > print(site.getsitepackages()[0])')
> >> >   RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" +
> >> > RbConfig::CONFIG["rubyarchhdrdir"] + " -I" +
> >> > RbConfig::CONFIG["rubyhdrdir"]')
> >> > +RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" +
> >> > RbConfig::CONFIG["libdir"] + " -lruby"')
> >>
> >> I'm trying to package 2.7-rc2 in debian and unfortunately this is
> >> not
> >> working out of the box for me. The library is not installed as
> >> -lruby
> >> but as -lruby-2.3 (for ruby 2.3). In addition the lib is not
> >> installed
> >> in /usr/lib.
> >>
> >> I can see in the RbConfig::CONFIG hash a key called LIBRUBYARG_SHARED
> >> or
> >> LIBRUBYARG which contains "-lruby-2.3". Also I see a "archlibdir" or
> >> "sitearchlibdir" key which contains the correct path to the lib (the
> >> multiarch path)
> >>
> >> RUBYLIBS ?= $(shell $@ -e 'puts "-L" + RbConfig::CONFIG["archlibdir"]
> >> +
> >> " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
> >>
> >> Could this be a possible alternatives for the other distributions?
> >
> > Assuming you mean $(RUBY) rather than $@ above, that works for me on
> > Fedora:
> > $ ruby -e 'puts "-L" + RbConfig::CONFIG["archlibdir"] + " " +
> > RbConfig::CONFIG["LIBRUBYARG_SHARED"]'
> > -L/usr/lib64 -lruby
> 
> On Arch Linux:
> 
> $ ruby -e 'puts RbConfig::CONFIG["LIBRUBYARG"]'
> -lruby
> $ ruby -e 'puts RbConfig::CONFIG["LIBRUBYARG_SHARED"]'
> -lruby
> $ ruby -e 'puts RbConfig::CONFIG["archlibdir"]'
> /usr/lib/x86_64-linux
> $ ls -l /usr/lib/x86_64-linux/libruby.so
> ls: cannot access '/usr/lib/x86_64-linux/libruby.so': No such file or directory
> $ ruby -e 'puts RbConfig::CONFIG["libdir"]'
> /usr/lib
> $ ls -l /usr/lib/libruby.so
> lrwxrwxrwx 1 root root 16 2017-04-22 15:40 /usr/lib/libruby.so ->
> libruby.so.2.4.1*
> 
> So replacing -lruby with RbConfig::CONFIG["LIBRUBYARG_SHARED"] and
> adding "-L" + RbConfig::CONFIG["archlibdir"] in RUBYLIBS definition
> seem to work fine.
> 
> Nicolas

Heres gentoo:
$ ruby -e 'puts RbConfig::CONFIG["LIBRUBYARG"]'
-lruby21
$ ruby -e 'puts RbConfig::CONFIG["LIBRUBYARG_SHARED"]'
-lruby21
$ ruby -e 'puts RbConfig::CONFIG["archlibdir"]'
/usr/lib64/x86_64-linux
$ stat /usr/lib64/x86_64-linux
stat: cannot stat '/usr/lib64/x86_64-linux': No such file or directory
$ ruby -e 'puts RbConfig::CONFIG["libdir"]'
/usr/lib64
$ ls -l /usr/lib64/libruby2*
-rw-r--r--. 1 root root 4078832 May  8 16:27 /usr/lib64/libruby21-static.a
lrwxrwxrwx. 1 root root      18 May  8 16:27 /usr/lib64/libruby21.so -> libruby21.so.2.1.0*
lrwxrwxrwx. 1 root root      18 May  8 16:27 /usr/lib64/libruby21.so.2.1 -> libruby21.so.2.1.0*
-rwxr-xr-x. 1 root root 2506160 May  8 16:27 /usr/lib64/libruby21.so.2.1.0*
-rw-r--r--. 1 root root 4588894 May  6 12:28 /usr/lib64/libruby22-static.a
lrwxrwxrwx. 1 root root      18 May  6 12:28 /usr/lib64/libruby22.so -> libruby22.so.2.2.0*
lrwxrwxrwx. 1 root root      18 May  6 12:28 /usr/lib64/libruby22.so.2.2 -> libruby22.so.2.2.0*
-rwxr-xr-x. 1 root root 2622488 May  6 12:28 /usr/lib64/libruby22.so.2.2.0*

$ qlist -Iv ruby
...
dev-lang/ruby-2.1.9
dev-lang/ruby-2.2.6
Stephen Smalley June 23, 2017, 2:14 p.m. UTC | #5
On Wed, 2017-06-21 at 22:27 +0800, Jason Zaman wrote:
> On Wed, Jun 21, 2017 at 04:02:29PM +0200, Nicolas Iooss wrote:
> > On Wed, Jun 21, 2017 at 3:42 PM, Stephen Smalley <sds@tycho.nsa.gov
> > > wrote:
> > > On Wed, 2017-06-21 at 11:38 +0200, Laurent Bigonville wrote:
> > > > Hello,
> > > > 
> > > > Le 14/11/16 à 22:28, Nicolas Iooss a écrit :
> > > > > When linking with -Wl,-no-undefined in LDFLAGS (in order to
> > > > > find
> > > > > possible link-time errors), the Ruby wrapper module needs to
> > > > > be
> > > > > linked
> > > > > with the libruby.so which is used by $(RUBY). Introduce a new
> > > > > RUBYLIBS
> > > > > variable to find this library.
> > > > > 
> > > > > Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
> > > > > ---
> > > > >   libselinux/src/Makefile  | 3 ++-
> > > > >   libsemanage/src/Makefile | 3 ++-
> > > > >   2 files changed, 4 insertions(+), 2 deletions(-)
> > > > > 
> > > > > diff --git a/libselinux/src/Makefile
> > > > > b/libselinux/src/Makefile
> > > > > index 4fe1f7002181..82a1010af2d8 100644
> > > > > --- a/libselinux/src/Makefile
> > > > > +++ b/libselinux/src/Makefile
> > > > > @@ -15,6 +15,7 @@ INCLUDEDIR ?= $(PREFIX)/include
> > > > >   PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
> > > > >   PYSITEDIR ?= $(DESTDIR)$(shell $(PYTHON) -c 'import site;
> > > > > print(site.getsitepackages()[0])')
> > > > >   RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" +
> > > > > RbConfig::CONFIG["rubyarchhdrdir"] + " -I" +
> > > > > RbConfig::CONFIG["rubyhdrdir"]')
> > > > > +RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" +
> > > > > RbConfig::CONFIG["libdir"] + " -lruby"')
> > > > 
> > > > I'm trying to package 2.7-rc2 in debian and unfortunately this
> > > > is
> > > > not
> > > > working out of the box for me. The library is not installed as
> > > > -lruby
> > > > but as -lruby-2.3 (for ruby 2.3). In addition the lib is not
> > > > installed
> > > > in /usr/lib.
> > > > 
> > > > I can see in the RbConfig::CONFIG hash a key called
> > > > LIBRUBYARG_SHARED
> > > > or
> > > > LIBRUBYARG which contains "-lruby-2.3". Also I see a
> > > > "archlibdir" or
> > > > "sitearchlibdir" key which contains the correct path to the lib
> > > > (the
> > > > multiarch path)
> > > > 
> > > > RUBYLIBS ?= $(shell $@ -e 'puts "-L" +
> > > > RbConfig::CONFIG["archlibdir"]
> > > > +
> > > > " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
> > > > 
> > > > Could this be a possible alternatives for the other
> > > > distributions?
> > > 
> > > Assuming you mean $(RUBY) rather than $@ above, that works for me
> > > on
> > > Fedora:
> > > $ ruby -e 'puts "-L" + RbConfig::CONFIG["archlibdir"] + " " +
> > > RbConfig::CONFIG["LIBRUBYARG_SHARED"]'
> > > -L/usr/lib64 -lruby
> > 
> > On Arch Linux:
> > 
> > $ ruby -e 'puts RbConfig::CONFIG["LIBRUBYARG"]'
> > -lruby
> > $ ruby -e 'puts RbConfig::CONFIG["LIBRUBYARG_SHARED"]'
> > -lruby
> > $ ruby -e 'puts RbConfig::CONFIG["archlibdir"]'
> > /usr/lib/x86_64-linux
> > $ ls -l /usr/lib/x86_64-linux/libruby.so
> > ls: cannot access '/usr/lib/x86_64-linux/libruby.so': No such file
> > or directory
> > $ ruby -e 'puts RbConfig::CONFIG["libdir"]'
> > /usr/lib
> > $ ls -l /usr/lib/libruby.so
> > lrwxrwxrwx 1 root root 16 2017-04-22 15:40 /usr/lib/libruby.so ->
> > libruby.so.2.4.1*
> > 
> > So replacing -lruby with RbConfig::CONFIG["LIBRUBYARG_SHARED"] and
> > adding "-L" + RbConfig::CONFIG["archlibdir"] in RUBYLIBS definition
> > seem to work fine.
> > 
> > Nicolas
> 
> Heres gentoo:
> $ ruby -e 'puts RbConfig::CONFIG["LIBRUBYARG"]'
> -lruby21
> $ ruby -e 'puts RbConfig::CONFIG["LIBRUBYARG_SHARED"]'
> -lruby21
> $ ruby -e 'puts RbConfig::CONFIG["archlibdir"]'
> /usr/lib64/x86_64-linux
> $ stat /usr/lib64/x86_64-linux
> stat: cannot stat '/usr/lib64/x86_64-linux': No such file or
> directory
> $ ruby -e 'puts RbConfig::CONFIG["libdir"]'
> /usr/lib64
> $ ls -l /usr/lib64/libruby2*
> -rw-r--r--. 1 root root 4078832 May  8 16:27 /usr/lib64/libruby21-
> static.a
> lrwxrwxrwx. 1 root root      18 May  8 16:27 /usr/lib64/libruby21.so
> -> libruby21.so.2.1.0*
> lrwxrwxrwx. 1 root root      18 May  8 16:27
> /usr/lib64/libruby21.so.2.1 -> libruby21.so.2.1.0*
> -rwxr-xr-x. 1 root root 2506160 May  8 16:27
> /usr/lib64/libruby21.so.2.1.0*
> -rw-r--r--. 1 root root 4588894 May  6 12:28 /usr/lib64/libruby22-
> static.a
> lrwxrwxrwx. 1 root root      18 May  6 12:28 /usr/lib64/libruby22.so
> -> libruby22.so.2.2.0*
> lrwxrwxrwx. 1 root root      18 May  6 12:28
> /usr/lib64/libruby22.so.2.2 -> libruby22.so.2.2.0*
> -rwxr-xr-x. 1 root root 2622488 May  6 12:28
> /usr/lib64/libruby22.so.2.2.0*
> 
> $ qlist -Iv ruby
> ...
> dev-lang/ruby-2.1.9
> dev-lang/ruby-2.2.6

So, what's the conclusion?  Do we have a consensus on replacing it as
proposed?  Looks like from the output above that archlibdir doesn't
actually work on gentoo or arch since the file doesn't exist there?
diff mbox

Patch

diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index 4fe1f7002181..82a1010af2d8 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -15,6 +15,7 @@  INCLUDEDIR ?= $(PREFIX)/include
 PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
 PYSITEDIR ?= $(DESTDIR)$(shell $(PYTHON) -c 'import site; print(site.getsitepackages()[0])')
 RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + RbConfig::CONFIG["rubyarchhdrdir"] + " -I" + RbConfig::CONFIG["rubyhdrdir"]')
+RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -lruby"')
 RUBYINSTALL ?= $(DESTDIR)$(shell $(RUBY) -e 'puts RbConfig::CONFIG["vendorarchdir"]')
 LIBBASE ?= $(shell basename $(LIBDIR))
 LIBSEPOLA ?= $(LIBDIR)/libsepol.a
@@ -133,7 +134,7 @@  $(SWIGSO): $(SWIGLOBJ)
 	$(CC) $(CFLAGS) -shared -o $@ $< -L. -lselinux $(LDFLAGS) -L$(LIBDIR)
 
 $(SWIGRUBYSO): $(SWIGRUBYLOBJ)
-	$(CC) $(CFLAGS) -shared -o $@ $^ -L. -lselinux $(LDFLAGS) -L$(LIBDIR)
+	$(CC) $(CFLAGS) -shared -o $@ $^ -L. -lselinux $(LDFLAGS) $(RUBYLIBS) -L$(LIBDIR)
 
 $(LIBA): $(OBJS)
 	$(AR) rcs $@ $^
diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
index c646f274cbc1..37d6eabbdae8 100644
--- a/libsemanage/src/Makefile
+++ b/libsemanage/src/Makefile
@@ -16,6 +16,7 @@  PYLIBVER ?= $(shell $(PYTHON) -c 'import sys;print("python%d.%d" % sys.version_i
 PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
 PYLIBDIR ?= $(LIBDIR)/$(PYLIBVER)
 RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + RbConfig::CONFIG["rubyarchhdrdir"] + " -I" + RbConfig::CONFIG["rubyhdrdir"]')
+RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -lruby"')
 RUBYINSTALL ?= $(DESTDIR)$(shell $(RUBY) -e 'puts RbConfig::CONFIG["vendorarchdir"]')
 
 LIBBASE=$(shell basename $(LIBDIR))
@@ -82,7 +83,7 @@  $(SWIGSO): $(SWIGLOBJ)
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $< -L. -lsemanage -L$(LIBDIR)
 
 $(SWIGRUBYSO): $(SWIGRUBYLOBJ)
-	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lsemanage -L$(LIBDIR)
+	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lsemanage $(RUBYLIBS) -L$(LIBDIR)
 
 $(LIBA): $(OBJS)
 	$(AR) rcs $@ $^