Fix link_whole of static libraries

pull/5985/head
Xavier Claessens 5 years ago committed by Xavier Claessens
parent 01569fee2e
commit f396c71c52
  1. 10
      mesonbuild/build.py
  2. 14
      run_unittests.py
  3. 9
      test cases/unit/69 static link/lib/func1.c
  4. 6
      test cases/unit/69 static link/lib/func2.c
  5. 8
      test cases/unit/69 static link/lib/meson.build
  6. 7
      test cases/unit/69 static link/meson.build
  7. 7
      test cases/unit/69 static link/test1.c

@ -1099,7 +1099,15 @@ You probably should put it in link_with instead.''')
raise InvalidArguments(msg + ' This is not possible in a cross build.')
else:
mlog.warning(msg + ' This will fail in cross build.')
self.link_whole_targets.append(t)
if isinstance(self, StaticLibrary):
# When we're a static library and we link_whole: to another static
# library, we need to add that target's objects to ourselves.
self.objects.append(t.extract_all_objects())
# Add internal and external deps
self.external_deps += t.external_deps
self.link_targets += t.link_targets
else:
self.link_whole_targets.append(t)
def add_pch(self, language, pchlist):
if not pchlist:

@ -5636,6 +5636,20 @@ c = ['{0}']
# TODO should someday be explicit about build platform only here
self.init(testdir, override_envvars=env)
def test_static_link(self):
# Build some libraries and install them
testdir = os.path.join(self.unit_test_dir, '69 static link/lib')
libdir = os.path.join(self.installdir, self.prefix[1:], self.libdir)
self.init(testdir)
self.install()
# Test that installed libraries works
self.new_builddir()
testdir = os.path.join(self.unit_test_dir, '69 static link')
self.init(testdir, extra_args=['-Dc_link_args="-L{}"'.format(libdir)])
self.build()
self.run_tests()
def should_run_cross_arm_tests():
return shutil.which('arm-linux-gnueabihf-gcc') and not platform.machine().lower().startswith('arm')

@ -0,0 +1,9 @@
int func1()
{
return 1;
}
int func1b()
{
return 1;
}

@ -0,0 +1,6 @@
int func1();
int func2()
{
return func1() + 1;
}

@ -0,0 +1,8 @@
project('test static link libs', 'c')
# libfunc2 should contain both func1() and func2() symbols
libfunc1 = static_library('func1', 'func1.c',
install : false)
libfunc2 = static_library('func2', 'func2.c',
link_whole : libfunc1,
install : true)

@ -0,0 +1,7 @@
project('test static link', 'c')
cc = meson.get_compiler('c')
# Verify that installed libfunc2.a is usable
func2_dep = cc.find_library('func2')
test('test1', executable('test1', 'test1.c', dependencies : func2_dep))

@ -0,0 +1,7 @@
int func1b();
int func2();
int main(int argc, char *argv[])
{
return func2() + func1b() == 3 ? 0 : 1;
}
Loading…
Cancel
Save