aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2018-07-04 06:06:09 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-07-04 10:39:14 +0000
commitf18af091898b43679af94b6e6facea559d97d096 (patch)
treed22b897c486f705303f465e9ad11b80725767b45
parent602e58d398c1126b792b4d725d481c67a519f9c1 (diff)
downloadmeson-f18af091898b43679af94b6e6facea559d97d096.zip
meson-f18af091898b43679af94b6e6facea559d97d096.tar.gz
meson-f18af091898b43679af94b6e6facea559d97d096.tar.bz2
find_library: Only run link test on system dirs
Paths provided to us by the user or by pkg-config can be (and must be) assumed to be usable since they might not be usable standalone. Closes https://github.com/mesonbuild/meson/issues/3832
-rw-r--r--mesonbuild/compilers/c.py27
-rw-r--r--test cases/common/146 C and CPP link/foo.cpp5
-rw-r--r--test cases/common/146 C and CPP link/foobar.c4
3 files changed, 24 insertions, 12 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index f3ce4d8..8af7abc 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -851,31 +851,36 @@ class CCompiler(Compiler):
args = ['-l' + libname]
if self.links(code, env, extra_args=args):
return args
- # Ensure that we won't modify the list that was passed to us
- extra_dirs = extra_dirs[:]
# Search in the system libraries too
- extra_dirs += self.get_library_dirs()
+ system_dirs = self.get_library_dirs()
# Not found or we want to use a specific libtype? Try to find the
# library file itself.
prefixes, suffixes = self.get_library_naming(env, libtype)
- # Triply-nested loop!
+ # Triply-nested loops!
for d in extra_dirs:
for suffix in suffixes:
for prefix in prefixes:
trial = os.path.join(d, prefix + libname + '.' + suffix)
- # as well as checking the path, we need to check compilation
- # with link-whole, as static libs (.a) need to be checked
- # to ensure they are the right architecture, e.g. 32bit or
- # 64-bit. Just a normal test link won't work as the .a file
- # doesn't seem to be checked by linker if there are no
- # unresolved symbols from the main C file.
+ if os.path.isfile(trial):
+ return [trial]
+ for d in system_dirs:
+ for suffix in suffixes:
+ for prefix in prefixes:
+ trial = os.path.join(d, prefix + libname + '.' + suffix)
+ # When searching the system paths used by the compiler, we
+ # need to check linking with link-whole, as static libs
+ # (.a) need to be checked to ensure they are the right
+ # architecture, e.g. 32bit or 64-bit.
+ # Just a normal test link won't work as the .a file doesn't
+ # seem to be checked by linker if there are no unresolved
+ # symbols from the main C file.
extra_link_args = self.get_link_whole_for([trial])
extra_link_args = self.linker_to_compiler_args(extra_link_args)
if (os.path.isfile(trial) and
self.links(code, env,
extra_args=extra_link_args)):
return [trial]
- # XXX: For OpenBSD and macOS we (may) need to search for libfoo.x.y.z.dylib
+ # XXX: For OpenBSD and macOS we (may) need to search for libfoo.x{,.y.z}.ext
return None
def find_library_impl(self, libname, env, extra_dirs, code, libtype):
diff --git a/test cases/common/146 C and CPP link/foo.cpp b/test cases/common/146 C and CPP link/foo.cpp
index d8b4dbb..9db7fb2 100644
--- a/test cases/common/146 C and CPP link/foo.cpp
+++ b/test cases/common/146 C and CPP link/foo.cpp
@@ -16,6 +16,9 @@
const int cnums[] = {0, 61};
+/* Provided by foobar.c */
+extern "C" int get_number_index (void);
+
template<typename T, int N>
std::vector<T> makeVector(const T (&data)[N])
{
@@ -27,5 +30,5 @@ namespace {
}
extern "C" int six_one(void) {
- return numbers[1];
+ return numbers[get_number_index ()];
}
diff --git a/test cases/common/146 C and CPP link/foobar.c b/test cases/common/146 C and CPP link/foobar.c
index bd6cb00..27928bf 100644
--- a/test cases/common/146 C and CPP link/foobar.c
+++ b/test cases/common/146 C and CPP link/foobar.c
@@ -17,6 +17,10 @@
#include "foo.hpp"
#include "foobar.h"
+int get_number_index (void) {
+ return 1;
+}
+
void mynumbers(int nums[]) {
nums[0] = forty_two();
nums[1] = six_one();