Repository: mesonbuild/meson

Issue:
intel compiler doesn't implement link_whole
Hi,
I got an error when including PETSc as external dependency. Here is my `meson.build`
```
project('xxx', 'cpp', default_options : ['cpp_std=c++11'])

pdep = dependency('PETSc')
```
this is what I get when I run meson

```The Meson build system
Version: 0.47.0
Source dir: /some/path/
Build dir: /some/path/build
Build type: native build
Project name: xxx
Project version: undefined
Native C++ compiler: icpc (intel 17.0.4 "icpc (ICC) 17.0.4 20170411")
Build machine cpu family: x86_64
Build machine cpu: x86_64
Found pkg-config: /usr/bin/pkg-config (0.27.1)

meson.build:5:0: ERROR:  Language C++ does not support linking whole archives.

A full log can be found at /some/path/build/meson-logs/meson-log.txt
```
and the log is
```
Build started at 2018-07-10T11:48:00.454242
Main binary: /bin/python3
Python system: Linux
The Meson build system
Version: 0.47.0
Source dir: /some/path
Build dir: /some/path/build
Build type: native build
Project name: xxx
Project version: undefined
Sanity testing C++ compiler: icpc
Is cross compiler: False.
Sanity check compiler command line: icpc /some/path/build/meson-private/sanitycheckcpp.cc -o /some/path/build/meson-private/sanitycheckcpp.exe
Sanity check compile stdout:

-----
Sanity check compile stderr:

-----
Running test binary command: /some/path/build/meson-private/sanitycheckcpp.exe
Native C++ compiler: icpc (intel 17.0.4 "icpc (ICC) 17.0.4 20170411")
Build machine cpu family: x86_64
Build machine cpu: x86_64
Found pkg-config: /usr/bin/pkg-config (0.27.1)
Determining dependency 'PETSc' with pkg-config executable '/usr/bin/pkg-config'
Called `/usr/bin/pkg-config --modversion PETSc` -> 0
3.9.2
Called `/usr/bin/pkg-config --cflags PETSc` -> 0
-I/...../petsc-3.9.2/arch-linux-c-dbg-g-real-avx-2-512-int64/include
Called `/usr/bin/pkg-config PETSc --libs` -> 0
-L/...../petsc-3.9.2/arch-linux-c-dbg-g-real-avx-2-512-int64/lib -lpetsc
Called `/usr/bin/pkg-config PETSc --libs` -> 0
-L/......./petsc-3.9.2/arch-linux-c-dbg-g-real-avx-2-512-int64/lib -lpetsc

meson.build:5:0: ERROR:  Language C++ does not support linking whole archives.
```

however, if I issue from the command line

```
icpc $(pkg-config --cflags --libs PETSc) meson-private/sanitycheckcpp.cc
```
it compiles and links..

What happens inside the call to `dependency`? Why I get that error and how can I solve it?

thanks




Discussion:
This happens because you're using ICC and the IntelCompiler class doesn't implement the `get_link_whole_for()` method. You can verify this by trying with gcc. The error message should be fixed, and that method needs to be implemented for the intel compiler. See: `mesonbuild/compilers/compilers.py`.
thanks @nirbheek, but I need to use intel compiler.. how should I fix this?
Might be as simple as 
```
def get_link_whole_for(self, args):
        return ['-Wl,--whole-archive'] + args + ['-Wl,--no-whole-archive']
```
or there is something I don't know about intel compilers?

> or there is something I don't know about intel compilers?

That should work, yes. Please test that locally and if it works I'll open a PR for it.

Resolving patch:
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -1561,6 +1561,9 @@ def openmp_flags(self):
         else:
             return ['-openmp']
 
+    def get_link_whole_for(self, args):
+        return GnuCompiler.get_link_whole_for(self, args)
+
 
 class ArmCompiler:
     # Functionality that is common to all ARM family compilers.


Test patch: