From 81544feffe4f3f1dc3e429db8bbff7054b31c3dd Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 15 Feb 2016 13:33:29 +0530 Subject: [PATCH 1/2] Explicitly use the import library while generating link args for a target --- mesonbuild/backend/backends.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index cab3b8f1a..c660f71b1 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -87,6 +87,14 @@ class Backend(): filename = os.path.join(targetdir, fname) return filename + def get_target_filename_for_linking(self, target): + # On some platforms (msvc for instance), the file that is used for + # dynamic linking is not the same as the dynamic library itself. This + # file is called an import library, and we want to link against that. + # On platforms where this distinction is not important, the import + # library is the same as the dynamic library itself. + return os.path.join(self.get_target_dir(target), target.get_import_filename()) + def get_target_dir(self, target): if self.environment.coredata.get_builtin_option('layout') == 'mirror': dirname = target.get_subdir() @@ -263,11 +271,7 @@ class Backend(): if not isinstance(d, build.StaticLibrary) and\ not isinstance(d, build.SharedLibrary): raise RuntimeError('Tried to link with a non-library target "%s".' % d.get_basename()) - fname = self.get_target_filename(d) - if compiler.id == 'msvc': - if fname.endswith('dll'): - fname = fname[:-3] + 'lib' - args.append(fname) + args.append(self.get_target_filename_for_linking(d)) # If you have executable e that links to shared lib s1 that links to shared library s2 # you have to specify s2 as well as s1 when linking e even if e does not directly use # s2. Gcc handles this case fine but Clang does not for some reason. Thus we need to From 21d471673addc6f61329ffe8ac6d4d919c6c70c6 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Sat, 20 Feb 2016 01:57:25 +0530 Subject: [PATCH 2/2] environment: When using MinGW-GCC, the import lib suffix is dll --- mesonbuild/environment.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 8df856ca7..c43c5e138 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -98,7 +98,12 @@ class Environment(): if (not cross and mesonlib.is_windows()) \ or (cross and self.cross_info.has_host() and self.cross_info.config['host_machine']['system'] == 'windows'): self.exe_suffix = 'exe' - self.import_lib_suffix = 'lib' + if self.detect_c_compiler(cross).get_id() == 'msvc': + self.import_lib_suffix = 'lib' + else: + # MinGW-GCC doesn't generate and can't link with a .lib + # It uses the DLL file as the import library + self.import_lib_suffix = 'dll' self.shared_lib_suffix = 'dll' self.shared_lib_prefix = '' self.static_lib_suffix = 'lib' @@ -546,7 +551,7 @@ class Environment(): def get_exe_suffix(self): return self.exe_suffix - # On Windows the library has suffix dll + # On Windows (MSVC) the library has suffix dll # but you link against a file that has suffix lib. def get_import_lib_suffix(self): return self.import_lib_suffix