From 907744d55e224f21d45d1dfac852db20de7d5532 Mon Sep 17 00:00:00 2001 From: Benjamin Redelings Date: Sat, 23 Dec 2017 13:22:23 -0800 Subject: [PATCH 1/3] Fix linking with clang++ on linux if install_rpath. --- mesonbuild/compilers/compilers.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 3d50eb060..ba76fad88 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -863,7 +863,12 @@ class Compiler: # Not needed on Windows or other platforms that don't use RPATH # https://github.com/mesonbuild/meson/issues/1897 lpaths = ':'.join([os.path.join(build_dir, p) for p in rpath_paths]) - args += ['-Wl,-rpath-link,' + lpaths] + + # clang expands '-Wl,rpath-link,' to ['-rpath-link'] instead of ['-rpath-link',''] + # This eats the next argument, which happens to be 'ldstdc++', causing link failures. + # We can dodge this problem by not adding any rpath_paths if the argument is empty. + if lpaths.strip() != '': + args += ['-Wl,-rpath-link,'+lpaths] return args From f3c182f07d7ad0fa1a0714b15fe2633950e81578 Mon Sep 17 00:00:00 2001 From: Benjamin Redelings Date: Sat, 23 Dec 2017 13:29:15 -0800 Subject: [PATCH 2/3] Add whitespace around '+'. --- mesonbuild/compilers/compilers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index ba76fad88..24ae3c91c 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -868,7 +868,7 @@ class Compiler: # This eats the next argument, which happens to be 'ldstdc++', causing link failures. # We can dodge this problem by not adding any rpath_paths if the argument is empty. if lpaths.strip() != '': - args += ['-Wl,-rpath-link,'+lpaths] + args += ['-Wl,-rpath-link,' + lpaths] return args From 55abe16d5a580d949fdd55d366409f6e4aef97a3 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Tue, 26 Dec 2017 03:23:26 +0530 Subject: [PATCH 3/3] unit tests: Test that relative install_rpath works correctly We weren't testing this with C++, so the breakage was missed. https://github.com/mesonbuild/meson/issues/2814 --- run_unittests.py | 7 +++++++ test cases/unit/11 build_rpath/meson.build | 9 ++++++++- test cases/unit/11 build_rpath/prog.cc | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test cases/unit/11 build_rpath/prog.cc diff --git a/run_unittests.py b/run_unittests.py index 9706b4514..17badaeb6 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -2288,11 +2288,18 @@ class LinuxlikeTests(BasePlatformTests): testdir = os.path.join(self.unit_test_dir, '11 build_rpath') self.init(testdir) self.build() + # C program RPATH build_rpath = get_rpath(os.path.join(self.builddir, 'prog')) self.assertEqual(build_rpath, '$ORIGIN/sub:/foo/bar') self.install() install_rpath = get_rpath(os.path.join(self.installdir, 'usr/bin/prog')) self.assertEqual(install_rpath, '/baz') + # C++ program RPATH + build_rpath = get_rpath(os.path.join(self.builddir, 'progcxx')) + self.assertEqual(build_rpath, '$ORIGIN/sub:/foo/bar') + self.install() + install_rpath = get_rpath(os.path.join(self.installdir, 'usr/bin/progcxx')) + self.assertEqual(install_rpath, 'baz') def test_pch_with_address_sanitizer(self): testdir = os.path.join(self.common_test_dir, '13 pch') diff --git a/test cases/unit/11 build_rpath/meson.build b/test cases/unit/11 build_rpath/meson.build index b84c259ab..c0bc3bd27 100644 --- a/test cases/unit/11 build_rpath/meson.build +++ b/test cases/unit/11 build_rpath/meson.build @@ -1,4 +1,4 @@ -project('build rpath', 'c') +project('build rpath', 'c', 'cpp') subdir('sub') executable('prog', 'prog.c', @@ -7,3 +7,10 @@ executable('prog', 'prog.c', install_rpath : '/baz', install : true, ) + +executable('progcxx', 'prog.cc', + link_with : l, + build_rpath : '/foo/bar', + install_rpath : 'baz', + install : true, + ) diff --git a/test cases/unit/11 build_rpath/prog.cc b/test cases/unit/11 build_rpath/prog.cc new file mode 100644 index 000000000..c7c212370 --- /dev/null +++ b/test cases/unit/11 build_rpath/prog.cc @@ -0,0 +1,8 @@ +#include +#include + +int main(int argc, char **argv) { + std::string* s = new std::string("Hello"); + delete s; + return 0; +}