aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/cpp.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-07-30 11:07:03 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2021-09-25 00:18:22 +0300
commit64c267c49c785a204730ca28141f1fe34bc1827a (patch)
treeca841d7940372425d499f955c06519aa1216b6f0 /mesonbuild/compilers/cpp.py
parentfee5cb697c77156f0dec4264ce846dd0d4f84fd5 (diff)
downloadmeson-64c267c49c785a204730ca28141f1fe34bc1827a.zip
meson-64c267c49c785a204730ca28141f1fe34bc1827a.tar.gz
meson-64c267c49c785a204730ca28141f1fe34bc1827a.tar.bz2
compilers: Add default search path stdlib_only_link_flags
This should be done in all cases of language_stdlib_only_link_flags, but I don't have access to all of the compilers to test it. This is required in cases where object files created by gfortran are linked using another compiler with a differen default search path, such as gfortran and clang together.
Diffstat (limited to 'mesonbuild/compilers/cpp.py')
-rw-r--r--mesonbuild/compilers/cpp.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index ecc911d..6cbc265 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -246,13 +246,31 @@ class ClangCPPCompiler(ClangCompiler, CPPCompiler):
return libs
return []
- def language_stdlib_only_link_flags(self) -> T.List[str]:
- return ['-lstdc++']
+ def language_stdlib_only_link_flags(self, env: 'Environment') -> T.List[str]:
+ # We need to apply the search prefix here, as these link arguments may
+ # be passed to a differen compiler with a different set of default
+ # search paths, such as when using Clang for C/C++ and gfortran for
+ # fortran,
+ search_dir = self._get_search_dirs(env)
+ search_dirs: T.List[str] = []
+ if search_dir is not None:
+ for d in search_dir.split()[-1][len('libraries: ='):].split(':'):
+ search_dirs.append(f'-L{d}')
+ return search_dirs + ['-lstdc++']
class AppleClangCPPCompiler(ClangCPPCompiler):
- def language_stdlib_only_link_flags(self) -> T.List[str]:
- return ['-lc++']
+ def language_stdlib_only_link_flags(self, env: 'Environment') -> T.List[str]:
+ # We need to apply the search prefix here, as these link arguments may
+ # be passed to a differen compiler with a different set of default
+ # search paths, such as when using Clang for C/C++ and gfortran for
+ # fortran,
+ search_dir = self._get_search_dirs(env)
+ search_dirs: T.List[str] = []
+ if search_dir is not None:
+ for d in search_dir.split()[-1][len('libraries: ='):].split(':'):
+ search_dirs.append(f'-L{d}')
+ return search_dirs + ['-lc++']
class EmscriptenCPPCompiler(EmscriptenMixin, ClangCPPCompiler):
@@ -396,7 +414,16 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:
return ['-fpch-preprocess', '-include', os.path.basename(header)]
- def language_stdlib_only_link_flags(self) -> T.List[str]:
+ def language_stdlib_only_link_flags(self, env: 'Environment') -> T.List[str]:
+ # We need to apply the search prefix here, as these link arguments may
+ # be passed to a differen compiler with a different set of default
+ # search paths, such as when using Clang for C/C++ and gfortran for
+ # fortran,
+ search_dir = self._get_search_dirs(env)
+ search_dirs: T.List[str] = []
+ if search_dir is not None:
+ for d in search_dir.split()[-1][len('libraries: ='):].split(':'):
+ search_dirs.append(f'-L{d}')
return ['-lstdc++']