Skip to content

Commit

Permalink
Fix library name mangling for non glibc Linux/UNIX
Browse files Browse the repository at this point in the history
It incorrectly appended ".so" to lib names like "libglib-2.0.so.0" on musl based Alpine Linux.
A bit research showed, that the notation of the ABI number after ".so" is common on at least:
* glibc based Linux
* non-glibc Linux
* Freebsd
* Solaris
* Netbsd

So we change this to exclude only Windows and Macos from this rule.

Raised and authored by John Cupitt.

Fixes #727
  • Loading branch information
larskanis committed Nov 11, 2019
1 parent f841beb commit 7f909c2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/ffi/library.rb
Expand Up @@ -47,7 +47,7 @@ def self.map_library_name(lib)

if lib && File.basename(lib) == lib
lib = Platform::LIBPREFIX + lib unless lib =~ /^#{Platform::LIBPREFIX}/
r = Platform::IS_GNU ? "\\.so($|\\.[1234567890]+)" : "\\.#{Platform::LIBSUFFIX}$"
r = Platform::IS_WINDOWS || Platform::IS_MAC ? "\\.#{Platform::LIBSUFFIX}$" : "\\.so($|\\.[1234567890]+)"
lib += ".#{Platform::LIBSUFFIX}" unless lib =~ /#{r}/
end

Expand All @@ -65,16 +65,16 @@ def initialize(function, *libraries)
#
# A basic usage may be:
# require 'ffi'
#
#
# module Hello
# extend FFI::Library
# ffi_lib FFI::Library::LIBC
# attach_function 'puts', [ :string ], :int
# end
#
#
# Hello.puts("Hello, World")
#
#
#
module Library
CURRENT_PROCESS = FFI::CURRENT_PROCESS
LIBC = FFI::Platform::LIBC
Expand All @@ -87,7 +87,7 @@ def self.extended(mod)
raise RuntimeError.new("must only be extended by module") unless mod.kind_of?(Module)
end


# @param [Array] names names of libraries to load
# @return [Array<DynamicLibrary>]
# @raise {LoadError} if a library cannot be opened
Expand Down

0 comments on commit 7f909c2

Please sign in to comment.