From 7dd302773dd2d6443ab52d608d1c86aef578f280 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 22 Nov 2019 13:26:53 -0500 Subject: Fix link_whole with a custom target t.pic won't be defined. We can only hope it has been built with -fPIC. Linker will complain otherwise any way. t.extract_all_objects_recurse() won't be defined. We could support this case by extracting the archive somewhere and pick object files. --- test cases/common/215 link custom/custom_stlib.py | 8 ++++++++ test cases/common/215 link custom/lib.c | 7 +++++++ test cases/common/215 link custom/meson.build | 2 ++ 3 files changed, 17 insertions(+) create mode 100644 test cases/common/215 link custom/lib.c (limited to 'test cases') diff --git a/test cases/common/215 link custom/custom_stlib.py b/test cases/common/215 link custom/custom_stlib.py index 2e61ac9..0157fb1 100755 --- a/test cases/common/215 link custom/custom_stlib.py +++ b/test cases/common/215 link custom/custom_stlib.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import shutil, sys, subprocess, argparse, pathlib +import platform parser = argparse.ArgumentParser() @@ -15,6 +16,12 @@ void flob(void) { } ''' +def get_pic_args(): + platname = platform.system().lower() + if platname in ['windows', 'mingw', 'darwin'] or platname.startswith('cygwin'): + return [] + return ['-fPIC'] + def generate_lib_gnulike(outfile, c_file, private_dir, compiler_array): if shutil.which('ar'): static_linker = 'ar' @@ -26,6 +33,7 @@ def generate_lib_gnulike(outfile, c_file, private_dir, compiler_array): sys.exit('Could not detect a static linker.') o_file = c_file.with_suffix('.o') compile_cmd = compiler_array + ['-c', '-g', '-O2', '-o', str(o_file), str(c_file)] + compile_cmd += get_pic_args() subprocess.check_call(compile_cmd) out_file = pathlib.Path(outfile) if out_file.exists(): diff --git a/test cases/common/215 link custom/lib.c b/test cases/common/215 link custom/lib.c new file mode 100644 index 0000000..585b6c9 --- /dev/null +++ b/test cases/common/215 link custom/lib.c @@ -0,0 +1,7 @@ +void flob(void); + +int foo(void) +{ + flob(); + return 0; +} diff --git a/test cases/common/215 link custom/meson.build b/test cases/common/215 link custom/meson.build index c8d3a6d..013da04 100644 --- a/test cases/common/215 link custom/meson.build +++ b/test cases/common/215 link custom/meson.build @@ -46,6 +46,8 @@ d_i = declare_dependency(link_with: clib[0]) exe2_i = executable('prog2_i', 'prog.c', dependencies: d_i) test('linkcustom2_i', exe2_i) +shared_library('lib1', 'lib.c', link_whole: clib) + # Link whole tests exe3_i = executable('prog3_i', 'prog.c', link_whole: clib[0]) -- cgit v1.1