Repository: mesonbuild/meson

Issue:
Boost: Misdetection of static and dynamic library on Ubuntu 18.04
It seems, that meson is misdetecting boost on Ubuntu 18.04.
See the MWE below.

**To Reproduce**
```
$ tree
.
├── meson.build
└── reproducer.cpp
```
meson.build:
```
project('reproducer', 'cpp',  version : '0.1',
  default_options : ['warning_level=3',
                     'cpp_std=c++14'])

py3_mod = import('python')
py3_inst = py3_mod.find_installation('python3', modules: ['graph_tool'])
boost_dep = dependency('boost', modules: ['python3'])
graph_tool_dep = dependency('graph-tool-py' + py3_inst.language_version(), include_type: 'system')

lib = library('reproducer', 'reproducer.cpp',
  dependencies: [py3_inst.dependency(), boost_dep, graph_tool_dep])
```
reproducer.cpp
```
#include <boost/python.hpp>
#include <Python.h>

#define PROJECT_NAME "reproducer"

boost::python::object some_function(PyObject* p) {
	return boost::python::object(boost::python::handle<>(p));
}
```

Output:
```
$ meson build
The Meson build system
Version: 0.54.2
Source dir: /home/srastaff/entrup/reproducer
Build dir: /home/srastaff/entrup/reproducer/build
Build type: native build
Project name: reproducer
Project version: 0.1
C++ compiler for the host machine: ccache c++ (gcc 7.5.0 "c++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0")
C++ linker for the host machine: c++ ld.bfd 2.30
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program python3 (graph_tool) found: YES (/usr/bin/python3) modules: graph_tool
Run-time dependency Boost (found: python36) found: YES 1.65.1 (/usr)
Found pkg-config: /usr/bin/pkg-config (0.29.1)
Run-time dependency graph-tool-py3.6 found: YES 2.31
Dependency python found: YES (pkgconfig)
Build targets in project: 1

Found ninja-1.10.0 at /usr/bin/ninja
$ cd build && ninja
[1/2] ccache c++ -Ireproducer@sha -I. -I.. -I/usr/include/python3.6m -I/usr/include/x86_64-linux-gnu/python3.6m -I/usr/include -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Wpedantic -std=c++14 -g -fPIC -pthread -isystem/usr/lib/python3/dist-packages/graph_tool/include -isystem/usr/lib/python3/dist-packages/graph_tool/include/boost-workaround -isystem/usr/lib/python3/dist-packages/graph_tool/include/pcg-cpp -isystem/usr/lib/python3/dist-packages/cairo/include -isystem/usr/include/python3.6m -isystem/usr/lib/python3/dist-packages/numpy/core/include -DBOOST_ALL_NO_LIB -MD -MQ 'reproducer@sha/reproducer.cpp.o' -MF 'reproducer@sha/reproducer.cpp.o.d' -o 'reproducer@sha/reproducer.cpp.o' -c ../reproducer.cpp
[2/2] c++  -o libreproducer.so 'reproducer@sha/reproducer.cpp.o' -Wl,--as-needed -Wl,--no-undefined -shared -fPIC -Wl,--start-group -Wl,-soname,libreproducer.so -lpython3.6m /usr/lib/x86_64-linux-gnu/libboost_python3-py36.a /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libpython3.6m.so /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libboost_python-py36.so -Wl,--end-group
FAILED: libreproducer.so 
c++  -o libreproducer.so 'reproducer@sha/reproducer.cpp.o' -Wl,--as-needed -Wl,--no-undefined -shared -fPIC -Wl,--start-group -Wl,-soname,libreproducer.so -lpython3.6m /usr/lib/x86_64-linux-gnu/libboost_python3-py36.a /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libpython3.6m.so /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libboost_python-py36.so -Wl,--end-group
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libboost_python3-py36.a(object_operators.o): relocation R_X86_64_PC32 against symbol `_Py_NoneStruct' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
```

**Expected behavior**
Linker call succeeds.

**Additional info**
Tracking down the problem, it seems that `/usr/lib/x86_64-linux-gnu/libboost_python3-py36.a` in the linker call is false. When I delete this part, the linker succeeds. The point seems to be that the [graph-tool](https://graph-tool.skewed.de/) dependency itself depends on Boost Python and pulls the shared library in and both libraries together result in a conflict. I don't see a benefit in the static library here. It seems to be included by mistake.

My boost libraries on this system:
```
$ ls -lh /usr/lib/x86_64-linux-gnu/libboost*
-rw-r--r-- 1 root root 2,4K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_atomic.a
lrwxrwxrwx 1 root root   25 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_atomic.so -> libboost_atomic.so.1.65.1
-rw-r--r-- 1 root root 5,7K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_atomic.so.1.65.1
-rw-r--r-- 1 root root  55K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_chrono.a
lrwxrwxrwx 1 root root   25 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_chrono.so -> libboost_chrono.so.1.65.1
-rw-r--r-- 1 root root  19K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_chrono.so.1.65.1
-rw-r--r-- 1 root root  11K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_context.a
lrwxrwxrwx 1 root root   26 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_context.so -> libboost_context.so.1.65.1
-rw-r--r-- 1 root root  11K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_context.so.1.65.1
-rw-r--r-- 1 root root 160K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_coroutine.a
lrwxrwxrwx 1 root root   28 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_coroutine.so -> libboost_coroutine.so.1.65.1
-rw-r--r-- 1 root root  71K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_coroutine.so.1.65.1
-rw-r--r-- 1 root root 148K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_date_time.a
lrwxrwxrwx 1 root root   28 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_date_time.so -> libboost_date_time.so.1.65.1
-rw-r--r-- 1 root root  67K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_date_time.so.1.65.1
-rw-r--r-- 1 root root 103K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.65.1
-rw-r--r-- 1 root root 735K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_graph.a
lrwxrwxrwx 1 root root   24 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_graph.so -> libboost_graph.so.1.65.1
-rw-r--r-- 1 root root 315K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_graph.so.1.65.1
-rw-r--r-- 1 root root 103K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_iostreams.so.1.65.1
-rw-r--r-- 1 root root 933K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_locale.so.1.65.1
-rw-r--r-- 1 root root 657K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_log_setup.so.1.65.1
-rw-r--r-- 1 root root 885K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_log.so.1.65.1
-rw-r--r-- 1 root root 163K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_prg_exec_monitor.a
lrwxrwxrwx 1 root root   35 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_prg_exec_monitor.so -> libboost_prg_exec_monitor.so.1.65.1
-rw-r--r-- 1 root root  63K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_prg_exec_monitor.so.1.65.1
-rw-r--r-- 1 root root 515K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_program_options.so.1.65.1
lrwxrwxrwx 1 root root   23 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_python3.a -> libboost_python3-py36.a
-rw-r--r-- 1 root root 570K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_python3-py36.a
lrwxrwxrwx 1 root root   31 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_python3-py36.so -> libboost_python3-py36.so.1.65.1
-rw-r--r-- 1 root root 251K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_python3-py36.so.1.65.1
lrwxrwxrwx 1 root root   24 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_python3.so -> libboost_python3-py36.so
lrwxrwxrwx 1 root root   22 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_python.a -> libboost_python-py27.a
-rw-r--r-- 1 root root 579K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_python-py27.a
lrwxrwxrwx 1 root root   30 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_python-py27.so -> libboost_python-py27.so.1.65.1
-rw-r--r-- 1 root root 255K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.65.1
lrwxrwxrwx 1 root root   23 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_python-py36.a -> libboost_python3-py36.a
lrwxrwxrwx 1 root root   24 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_python-py36.so -> libboost_python3-py36.so
lrwxrwxrwx 1 root root   23 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_python.so -> libboost_python-py27.so
-rw-r--r-- 1 root root 2,8M Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_regex.a
lrwxrwxrwx 1 root root   24 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_regex.so -> libboost_regex.so.1.65.1
-rw-r--r-- 1 root root 1,1M Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_regex.so.1.65.1
-rw-r--r-- 1 root root 1,1M Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_serialization.a
lrwxrwxrwx 1 root root   32 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_serialization.so -> libboost_serialization.so.1.65.1
-rw-r--r-- 1 root root 247K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_serialization.so.1.65.1
-rw-r--r-- 1 root root  63K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_system.a
lrwxrwxrwx 1 root root   25 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_system.so -> libboost_system.so.1.65.1
-rw-r--r-- 1 root root  19K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1
-rw-r--r-- 1 root root 2,2M Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_test_exec_monitor.a
-rw-r--r-- 1 root root 366K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_thread.a
lrwxrwxrwx 1 root root   25 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_thread.so -> libboost_thread.so.1.65.1
-rw-r--r-- 1 root root 147K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.65.1
-rw-r--r-- 1 root root 2,2M Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.a
lrwxrwxrwx 1 root root   38 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so -> libboost_unit_test_framework.so.1.65.1
-rw-r--r-- 1 root root 804K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.65.1
-rw-r--r-- 1 root root 738K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_wserialization.a
lrwxrwxrwx 1 root root   33 Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_wserialization.so -> libboost_wserialization.so.1.65.1
-rw-r--r-- 1 root root 171K Mär  6  2018 /usr/lib/x86_64-linux-gnu/libboost_wserialization.so.1.65.1
```

The pkg-config of graph-tool:
```
$ cat /usr/lib/pkgconfig/graph-tool-py3.6.pc          
# generated by configure / remove this line to disable regeneration
prefix=/usr
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
libdir=${exec_prefix}/lib
datarootdir=${prefix}/share
datadir=${datarootdir}
sysconfdir=/etc
includedir=${prefix}/include
package=graph-tool
suffix=

Name: graph-tool-py3.6
Description: graph-tool Python library
Version: 2.31
Requires: 
Libs: -L${libdir}  -L/usr/lib -lpython3.6m -lboost_python-py36
Cflags: -I${includedir} -I/usr/lib/python3/dist-packages/graph_tool/include -I/usr/lib/python3/dist-packages/graph_tool/include/boost-workaround -I/usr/lib/python3/dist-packages/graph_tool/include/pcg-cpp -I/usr/lib/python3/dist-packages/cairo/include -I/usr/include/python3.6m -pthread -I/usr/include -I/usr/include -I/usr/lib/python3/dist-packages/numpy/core/include
```

My meson log output:
```
$ cat meson-logs/meson-log.txt 
Build started at 2020-05-19T18:46:10.778235
Main binary: /usr/bin/python3
Build Options: 
Python system: Linux
The Meson build system
Version: 0.54.2
Source dir: /home/srastaff/entrup/reproducer
Build dir: /home/srastaff/entrup/reproducer/build
Build type: native build
None of 'PKG_CONFIG_PATH' are defined in the environment, not changing global flags.
None of 'PKG_CONFIG_PATH' are defined in the environment, not changing global flags.
Project name: reproducer
Project version: 0.1
None of 'CXX' are defined in the environment, not changing global flags.
None of 'CXXFLAGS' are defined in the environment, not changing global flags.
None of 'LDFLAGS' are defined in the environment, not changing global flags.
None of 'CPPFLAGS' are defined in the environment, not changing global flags.
None of 'CXX_LD' are defined in the environment, not changing global flags.
Sanity testing C++ compiler: ccache c++
Is cross compiler: False.
Sanity check compiler command line: ccache c++ /home/srastaff/entrup/reproducer/build/meson-private/sanitycheckcpp.cc -o /home/srastaff/entrup/reproducer/build/meson-private/sanitycheckcpp.exe -pipe -D_FILE_OFFSET_BITS=64
Sanity check compile stdout:

-----
Sanity check compile stderr:

-----
Running test binary command: /home/srastaff/entrup/reproducer/build/meson-private/sanitycheckcpp.exe
C++ compiler for the build machine: ccache c++ (gcc 7.5.0 "c++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0")
C++ linker for the build machine: c++ ld.bfd 2.30
None of 'AR' are defined in the environment, not changing global flags.
None of 'CXX' are defined in the environment, not changing global flags.
None of 'CXXFLAGS' are defined in the environment, not changing global flags.
None of 'LDFLAGS' are defined in the environment, not changing global flags.
None of 'CPPFLAGS' are defined in the environment, not changing global flags.
None of 'CXX_LD' are defined in the environment, not changing global flags.
Sanity testing C++ compiler: ccache c++
Is cross compiler: False.
Sanity check compiler command line: ccache c++ /home/srastaff/entrup/reproducer/build/meson-private/sanitycheckcpp.cc -o /home/srastaff/entrup/reproducer/build/meson-private/sanitycheckcpp.exe -pipe -D_FILE_OFFSET_BITS=64
Sanity check compile stdout:

-----
Sanity check compile stderr:

-----
Running test binary command: /home/srastaff/entrup/reproducer/build/meson-private/sanitycheckcpp.exe
C++ compiler for the host machine: ccache c++ (gcc 7.5.0 "c++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0")
C++ linker for the host machine: c++ ld.bfd 2.30
None of 'AR' are defined in the environment, not changing global flags.
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: x86_64
Host machine cpu: x86_64
Target machine cpu family: x86_64
Target machine cpu: x86_64
Program python3 (graph_tool) found: YES (/usr/bin/python3) modules: graph_tool
Checking potential boost root /usr/include/c++
Checking potential boost root /usr/include/x86_64-linux-gnu/c++
Checking potential boost root /usr/include/c++/7
Checking potential boost root /usr/lib/gcc/x86_64-linux-gnu/7
Checking potential boost root /usr/local
Checking potential boost root /usr/include
Running compile:
Working directory:  /home/srastaff/entrup/reproducer/build/meson-private/tmpgs992j61
Command line:  ccache c++ /home/srastaff/entrup/reproducer/build/meson-private/tmpgs992j61/testfile.cpp -o /home/srastaff/entrup/reproducer/build/meson-private/tmpgs992j61/output.obj -pipe -c -D_FILE_OFFSET_BITS=64 -O0 -fpermissive --print-search-dirs 

Code:
 
Compiler stdout:
 install: /usr/lib/gcc/x86_64-linux-gnu/7/
programs: =/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/bin/
libraries: =/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/:/lib/x86_64-linux-gnu/7/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/7/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../:/lib/:/usr/lib/

Compiler stderr:
 
  - potential library dirs: ['/usr/include/libdrm', '/usr/include/libdwarf', '/usr/include/libiberty', '/usr/include/libltdl', '/usr/include/libpng', '/usr/include/libpng16']
  - potential include dirs: ['/usr/include']
  - found boost 1.65.1 include dir: /usr/include
  - filtered library list:
  - found:
  - NOT found:
    - boost_python3
Checking potential boost root /usr
  - potential library dirs: ['/usr/lib/gcc/x86_64-linux-gnu/7', '/usr/lib/x86_64-linux-gnu', '/usr/lib']
  - potential include dirs: ['/usr/include']
  - found boost library dir: /usr/lib/x86_64-linux-gnu
  - found boost 1.65.1 include dir: /usr/include
  - filtered library list:
    - <LIB: SM ------ ??? ? x_xx boost_atomic                     /usr/lib/x86_64-linux-gnu/libboost_atomic.a>
    - <LIB: SM ------ ??? ? x_xx boost_chrono                     /usr/lib/x86_64-linux-gnu/libboost_chrono.a>
    - <LIB: SM ------ ??? ? x_xx boost_context                    /usr/lib/x86_64-linux-gnu/libboost_context.a>
    - <LIB: SM ------ ??? ? x_xx boost_coroutine                  /usr/lib/x86_64-linux-gnu/libboost_coroutine.a>
    - <LIB: SM ------ ??? ? x_xx boost_date_time                  /usr/lib/x86_64-linux-gnu/libboost_date_time.a>
    - <LIB: SM ------ ??? ? x_xx boost_graph                      /usr/lib/x86_64-linux-gnu/libboost_graph.a>
    - <LIB: SM ------ ??? ? x_xx boost_prg_exec_monitor           /usr/lib/x86_64-linux-gnu/libboost_prg_exec_monitor.a>
    - <LIB: SM ------ ??? ? x_xx boost_python27                   /usr/lib/x86_64-linux-gnu/libboost_python-py27.a>
    - <LIB: SM ------ ??? ? x_xx boost_python36                   /usr/lib/x86_64-linux-gnu/libboost_python3-py36.a>
    - <LIB: SM ------ ??? ? x_xx boost_regex                      /usr/lib/x86_64-linux-gnu/libboost_regex.a>
    - <LIB: SM ------ ??? ? x_xx boost_serialization              /usr/lib/x86_64-linux-gnu/libboost_serialization.a>
    - <LIB: SM ------ ??? ? x_xx boost_system                     /usr/lib/x86_64-linux-gnu/libboost_system.a>
    - <LIB: SM ------ ??? ? x_xx boost_test_exec_monitor          /usr/lib/x86_64-linux-gnu/libboost_test_exec_monitor.a>
    - <LIB: SM ------ ??? ? x_xx boost_thread                     /usr/lib/x86_64-linux-gnu/libboost_thread.a>
    - <LIB: SM ------ ??? ? x_xx boost_unit_test_framework        /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.a>
    - <LIB: SM ------ ??? ? x_xx boost_wserialization             /usr/lib/x86_64-linux-gnu/libboost_wserialization.a>
  - found:
    - boost_python36           link=['/usr/lib/x86_64-linux-gnu/libboost_python3-py36.a'] comp=[]
  - final compile args: ['-I/usr/include', '-DBOOST_ALL_NO_LIB']
  - final link args:    ['/usr/lib/x86_64-linux-gnu/libboost_python3-py36.a']
Run-time dependency Boost (found: python36) found: YES 1.65.1 (/usr)
Pkg-config binary for MachineChoice.HOST is not cached.
None of 'PKG_CONFIG' are defined in the environment, not changing global flags.
Pkg-config binary missing from cross or native file, or env var undefined.
Trying a default Pkg-config fallback at pkg-config
Trying pkg-config binary pkg-config for machine MachineChoice.HOST at ['/usr/bin/pkg-config']
Found pkg-config: /usr/bin/pkg-config (0.29.1)
Determining dependency 'graph-tool-py3.6' with pkg-config executable '/usr/bin/pkg-config'
PKG_CONFIG_PATH: 
Called `/usr/bin/pkg-config --modversion graph-tool-py3.6` -> 0
2.31
PKG_CONFIG_PATH: 
Called `/usr/bin/pkg-config --cflags graph-tool-py3.6` -> 0
-pthread -I/usr/lib/python3/dist-packages/graph_tool/include -I/usr/lib/python3/dist-packages/graph_tool/include/boost-workaround -I/usr/lib/python3/dist-packages/graph_tool/include/pcg-cpp -I/usr/lib/python3/dist-packages/cairo/include -I/usr/include/python3.6m -I/usr/lib/python3/dist-packages/numpy/core/include
PKG_CONFIG_PATH: 
Called `/usr/bin/pkg-config graph-tool-py3.6 --libs` -> 0
-L/usr/lib -lpython3.6m -lboost_python-py36
PKG_CONFIG_PATH: 
Called `/usr/bin/pkg-config graph-tool-py3.6 --libs` -> 0
-lpython3.6m -lboost_python-py36
None of 'PKG_CONFIG_PATH' are defined in the environment, not changing global flags.
Running compile:
Working directory:  /home/srastaff/entrup/reproducer/build/meson-private/tmpyt4gmooo
Command line:  ccache c++ /home/srastaff/entrup/reproducer/build/meson-private/tmpyt4gmooo/testfile.cpp -o /home/srastaff/entrup/reproducer/build/meson-private/tmpyt4gmooo/output.exe -pipe -D_FILE_OFFSET_BITS=64 -O0 -fpermissive 

Code:
 #include<stdio.h>
        
        int main(void) {
            printf("%ld\n", (long)(sizeof(void *)));
            return 0;
        };
Compiler stdout:
 
Compiler stderr:
 
Program stdout:

8

Program stderr:


Run-time dependency graph-tool-py3.6 found: YES 2.31
Pkg-config binary for MachineChoice.HOST is cached.
Determining dependency 'python-3.6m' with pkg-config executable '/usr/bin/pkg-config'
PKG_CONFIG_PATH: 
Called `/usr/bin/pkg-config --modversion python-3.6m` -> 0
3.6
PKG_CONFIG_PATH: 
Called `/usr/bin/pkg-config --cflags python-3.6m` -> 0
-I/usr/include/python3.6m -I/usr/include/x86_64-linux-gnu/python3.6m
PKG_CONFIG_PATH: 
Called `/usr/bin/pkg-config python-3.6m --libs` -> 0
-lpython3.6m
PKG_CONFIG_PATH: 
Called `/usr/bin/pkg-config python-3.6m --libs` -> 0
-lpython3.6m
None of 'PKG_CONFIG_PATH' are defined in the environment, not changing global flags.
Running compile:
Working directory:  /home/srastaff/entrup/reproducer/build/meson-private/tmp5lh26n4n
Command line:  ccache c++ /home/srastaff/entrup/reproducer/build/meson-private/tmp5lh26n4n/testfile.cpp -o /home/srastaff/entrup/reproducer/build/meson-private/tmp5lh26n4n/output.exe -pipe -D_FILE_OFFSET_BITS=64 -O0 -fpermissive -Wl,--start-group -lpython3.6m -Wl,--end-group -Wl,--allow-shlib-undefined 

Code:
 int main(void) { return 0; }
Compiler stdout:
 
Compiler stderr:
 
Found "python-3.6m" via pkgconfig lookup in LIBPC (/usr/lib/x86_64-linux-gnu/pkgconfig)
Dependency python found: YES (pkgconfig)
Build targets in project: 1

Found ninja-1.10.0 at /usr/bin/ninja
Running compile:
Working directory:  /tmp/tmp03vcxbmg
Command line:  ccache c++ /tmp/tmp03vcxbmg/testfile.cpp -o /tmp/tmp03vcxbmg/output.obj -pipe -D_FILE_OFFSET_BITS=64 -c -std=c++14 

Code:
 int i = static_cast<int>(0);
Compiler stdout:
 
Compiler stderr:
 
Compiler accepts -std=c++14: YES
None of 'STRIP' are defined in the environment, not changing global flags.
None of 'STRIP' are defined in the environment, not changing global flags.
```

**system parameters**
* OS: Ubuntu 18.04
* Python: 3.6
* `meson --version`: 0.54.2
* `ninja --version`: 1.10.0



Discussion:
As you have already pointed out, the main problem appears to be that graph-tool already automatically adds boost as a dependency. However, meson is not (and will never be) aware of this, since detecting such conflicts is far from trivial. That being said, meson should probably find the shared boost version by default.

You should be able to work around this by specifying `static: false` for your `boost_dep` (or removing it completely, since it appears to be not required, at least for the example you provided).
> As you have already pointed out, the main problem appears to be that graph-tool already automatically adds boost as a dependency. However, meson is not (and will never be) aware of this, since detecting such conflicts is far from trivial.

Ok. This is a new bug for me. Appearently, Meson has changed its behaviour here with release 0.54. With 0.53.2 the specific line of ninja is:
```
c++  -o libreproducer.so 'reproducer@sha/reproducer.cpp.o' -Wl,--as-needed -Wl,--no-undefined -shared -fPIC -Wl,--start-group -Wl,-soname,libreproducer.so -lpython3.6m -lboost_python3 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libpython3.6m.so /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libboost_python-py36.so -Wl,--end-group
```

> That being said, meson should probably find the shared boost version by default.

I would expect that, if your target is a shared library, the dependencies are also linked in as shared library.


> You should be able to work around this by specifying `static: false` for your `boost_dep` (or removing it completely, since it appears to be not required, at least for the example you provided).

Yes, you are right. That works (dropping the dependency does not work, since I also need other parts of boost in my real project).


Resolving patch:
diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py
--- a/mesonbuild/dependencies/boost.py
+++ b/mesonbuild/dependencies/boost.py
@@ -189,13 +189,13 @@ def __repr__(self) -> str:
     def __lt__(self, other: T.Any) -> bool:
         if isinstance(other, BoostLibraryFile):
             return (
-                self.mod_name, self.version_lib, self.arch, self.static,
+                self.mod_name, self.static, self.version_lib, self.arch,
                 not self.mt, not self.runtime_static,
                 not self.debug, self.runtime_debug, self.python_debug,
                 self.stlport, self.deprecated_iostreams,
                 self.name,
             ) < (
-                other.mod_name, other.version_lib, other.arch, other.static,
+                other.mod_name, other.static, other.version_lib, other.arch,
                 not other.mt, not other.runtime_static,
                 not other.debug, other.runtime_debug, other.python_debug,
                 other.stlport, other.deprecated_iostreams,


Test patch: