From 2549ed8290bd1f754964cc2e1c706d431ad4259a Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 15 Aug 2016 17:15:04 +0530 Subject: [PATCH 1/2] Add a test to find libfoo.X.dylib via -lfoo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Alex Băluț reported that on OS X libfoo.0.dylib cannot be found as -lfoo by the linker, and you must use -lfoo.0 instead. Add a test for this so the CI can catch such problems. The next commit will contain the fix. --- test cases/osx/2 library versions/exe.orig.c | 4 +++ .../2 library versions/installed_files.txt | 6 ++-- test cases/osx/2 library versions/meson.build | 31 ++++++++++++++++--- 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 test cases/osx/2 library versions/exe.orig.c diff --git a/test cases/osx/2 library versions/exe.orig.c b/test cases/osx/2 library versions/exe.orig.c new file mode 100644 index 000000000..1a8cc627e --- /dev/null +++ b/test cases/osx/2 library versions/exe.orig.c @@ -0,0 +1,4 @@ +int +main (int argc, char *argv[]) +{ +} diff --git a/test cases/osx/2 library versions/installed_files.txt b/test cases/osx/2 library versions/installed_files.txt index 66470ab59..4d5850244 100644 --- a/test cases/osx/2 library versions/installed_files.txt +++ b/test cases/osx/2 library versions/installed_files.txt @@ -1,4 +1,4 @@ -usr/lib/libsome.0.dylib +usr/lib/libsome.dylib usr/lib/libnoversion.dylib -usr/lib/libonlyversion.1.dylib -usr/lib/libonlysoversion.5.dylib +usr/lib/libonlyversion.dylib +usr/lib/libonlysoversion.dylib diff --git a/test cases/osx/2 library versions/meson.build b/test cases/osx/2 library versions/meson.build index 504aa4e22..107b46758 100644 --- a/test cases/osx/2 library versions/meson.build +++ b/test cases/osx/2 library versions/meson.build @@ -1,18 +1,41 @@ project('library versions', 'c') -shared_library('some', 'lib.c', +some = shared_library('some', 'lib.c', version : '1.2.3', soversion : '0', install : true) -shared_library('noversion', 'lib.c', +noversion = shared_library('noversion', 'lib.c', install : true) -shared_library('onlyversion', 'lib.c', +onlyversion = shared_library('onlyversion', 'lib.c', version : '1.4.5', install : true) -shared_library('onlysoversion', 'lib.c', +onlysoversion = shared_library('onlysoversion', 'lib.c', # Also test that int soversion is acceptable soversion : 5, install : true) + +# Hack to make the executables below depend on the shared libraries above +# without actually adding them as `link_with` dependencies since we want to try +# linking to them with -lfoo linker arguments. +out = custom_target('library-dependency-hack', + input : 'exe.orig.c', + output : 'exe.c', + depends : [some, noversion, onlyversion, onlysoversion], + command : ['cp', '@INPUT@', '@OUTPUT@']) + +# Manually test if the linker can find the above libraries +# i.e., whether they were generated with the right naming scheme +executable('manuallink1', out, + link_args : ['-L.', '-lsome']) + +executable('manuallink2', out, + link_args : ['-L.', '-lnoversion']) + +executable('manuallink3', out, + link_args : ['-L.', '-lonlyversion']) + +executable('manuallink4', out, + link_args : ['-L.', '-lonlysoversion']) From 5f3097a4928056c009b8fb30a4c6725a93e1e858 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Tue, 16 Aug 2016 15:53:55 +0530 Subject: [PATCH 2/2] Don't add the soversion to the dylib filename on OS X Doing so messes up library search with -lfoo. See: https://github.com/mesonbuild/meson/pull/680 --- mesonbuild/build.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 6a4f37596..6025d9d93 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -814,12 +814,10 @@ class SharedLibrary(BuildTarget): elif for_darwin(is_cross, env): prefix = 'lib' suffix = 'dylib' - if self.soversion: - # libfoo.X.dylib - self.filename_tpl = '{0.prefix}{0.name}.{0.soversion}.{0.suffix}' - else: - # libfoo.dylib - self.filename_tpl = '{0.prefix}{0.name}.{0.suffix}' + # libfoo.dylib + self.filename_tpl = '{0.prefix}{0.name}.{0.suffix}' + # On OS X, the filename should never have the soversion + # See: https://github.com/mesonbuild/meson/pull/680 else: prefix = 'lib' suffix = 'so'